file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.loc_includes_union_r | val loc_includes_union_r (s s1 s2:loc) : Lemma
(requires (loc_includes s s1 /\ loc_includes s s2))
(ensures (loc_includes s (loc_union s1 s2)))
[SMTPat (loc_includes s (loc_union s1 s2))] | val loc_includes_union_r (s s1 s2:loc) : Lemma
(requires (loc_includes s s1 /\ loc_includes s s2))
(ensures (loc_includes s (loc_union s1 s2)))
[SMTPat (loc_includes s (loc_union s1 s2))] | let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 237,
"start_col": 0,
"start_line": 237
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.PPC64LE.Memory.loc -> s1: Vale.PPC64LE.Memory.loc -> s2: Vale.PPC64LE.Memory.loc
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.loc_includes s s1 /\ Vale.PPC64LE.Memory.loc_includes s s2)
(ensures Vale.PPC64LE.Memory.loc_includes s (Vale.PPC64LE.Memory.loc_union s1 s2))
[SMTPat (Vale.PPC64LE.Memory.loc_includes s (Vale.PPC64LE.Memory.loc_union s1 s2))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_union_r",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_union_r s s1 s2 =
| M.loc_includes_union_r s s1 s2 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.same_underlying_seq | val same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t)
: Lemma
(requires
Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc))
(DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) | val same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t)
: Lemma
(requires
Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc))
(DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) | let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 222,
"start_col": 0,
"start_line": 203
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap ->
b: Vale.PPC64LE.Memory.buffer t
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.equal (LowStar.BufferView.Down.as_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih
h1))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(LowStar.BufferView.Down.as_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih h2))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b))))
(ensures
FStar.Seq.Base.equal (Vale.PPC64LE.Memory.buffer_as_seq h1 b)
(Vale.PPC64LE.Memory.buffer_as_seq h2 b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.buffer",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Vale.PPC64LE.Memory.buffer_length",
"Prims.unit",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.eq2",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"FStar.Seq.Base.index",
"Vale.PPC64LE.Memory.buffer_as_seq",
"FStar.Seq.Base.equal",
"FStar.UInt8.t",
"LowStar.BufferView.Down.as_seq",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Prims.bool",
"Prims.op_Addition",
"LowStar.BufferView.Up.as_seq_sel",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.BufferView.Up.get_sel",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"Vale.PPC64LE.Memory.uint_view",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.__proj__Buffer__item__bsrc"
] | [] | false | false | true | false | false | let same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t)
: Lemma
(requires
Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc))
(DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) =
| let db = get_downview b.bsrc in
let rec aux (i: nat{i <= buffer_length b})
: Lemma
(requires
(forall (j: nat{j < i}).
Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures
(forall (j: nat{j < buffer_length b}).
Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b
then ()
else
(let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i + 1))
in
aux 0 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.loc_includes_none | val loc_includes_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)] | val loc_includes_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)] | let loc_includes_none s = M.loc_includes_none s | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 240,
"start_col": 0,
"start_line": 240
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.PPC64LE.Memory.loc
-> FStar.Pervasives.Lemma
(ensures Vale.PPC64LE.Memory.loc_includes s Vale.PPC64LE.Memory.loc_none)
[SMTPat (Vale.PPC64LE.Memory.loc_includes s Vale.PPC64LE.Memory.loc_none)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_none",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_none s =
| M.loc_includes_none s | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.loc_includes_union_l_buffer | val loc_includes_union_l_buffer (#t:base_typ) (s1 s2:loc) (b:buffer t) : Lemma
(requires (loc_includes s1 (loc_buffer b) \/ loc_includes s2 (loc_buffer b)))
(ensures (loc_includes (loc_union s1 s2) (loc_buffer b)))
[SMTPat (loc_includes (loc_union s1 s2) (loc_buffer b))] | val loc_includes_union_l_buffer (#t:base_typ) (s1 s2:loc) (b:buffer t) : Lemma
(requires (loc_includes s1 (loc_buffer b) \/ loc_includes s2 (loc_buffer b)))
(ensures (loc_includes (loc_union s1 s2) (loc_buffer b)))
[SMTPat (loc_includes (loc_union s1 s2) (loc_buffer b))] | let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 239,
"start_col": 0,
"start_line": 239
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Vale.PPC64LE.Memory.loc -> s2: Vale.PPC64LE.Memory.loc -> b: Vale.PPC64LE.Memory.buffer t
-> FStar.Pervasives.Lemma
(requires
Vale.PPC64LE.Memory.loc_includes s1 (Vale.PPC64LE.Memory.loc_buffer b) \/
Vale.PPC64LE.Memory.loc_includes s2 (Vale.PPC64LE.Memory.loc_buffer b))
(ensures
Vale.PPC64LE.Memory.loc_includes (Vale.PPC64LE.Memory.loc_union s1 s2)
(Vale.PPC64LE.Memory.loc_buffer b))
[
SMTPat (Vale.PPC64LE.Memory.loc_includes (Vale.PPC64LE.Memory.loc_union s1 s2)
(Vale.PPC64LE.Memory.loc_buffer b))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.loc",
"Vale.PPC64LE.Memory.buffer",
"LowStar.Monotonic.Buffer.loc_includes_union_l",
"Vale.PPC64LE.Memory.loc_buffer",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_union_l_buffer #t s1 s2 b =
| M.loc_includes_union_l s1 s2 (loc_buffer b) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_refl | val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies s h h)] | val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies s h h)] | let modifies_refl s h = M.modifies_refl s (_ih h).hs | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 241,
"start_col": 0,
"start_line": 241
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.PPC64LE.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (ensures Vale.PPC64LE.Memory.modifies s h h)
[SMTPat (Vale.PPC64LE.Memory.modifies s h h)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"LowStar.Monotonic.Buffer.modifies_refl",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Prims.unit"
] | [] | true | false | true | false | false | let modifies_refl s h =
| M.modifies_refl s (_ih h).hs | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_goal_directed_refl | val modifies_goal_directed_refl (s:loc) (h:vale_heap) : Lemma
(modifies_goal_directed s h h)
[SMTPat (modifies_goal_directed s h h)] | val modifies_goal_directed_refl (s:loc) (h:vale_heap) : Lemma
(modifies_goal_directed s h h)
[SMTPat (modifies_goal_directed s h h)] | let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 242,
"start_col": 0,
"start_line": 242
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.PPC64LE.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (ensures Vale.PPC64LE.Memory.modifies_goal_directed s h h)
[SMTPat (Vale.PPC64LE.Memory.modifies_goal_directed s h h)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"LowStar.Monotonic.Buffer.modifies_refl",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Prims.unit"
] | [] | true | false | true | false | false | let modifies_goal_directed_refl s h =
| M.modifies_refl s (_ih h).hs | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_loc_includes | val modifies_loc_includes (s1:loc) (h h':vale_heap) (s2:loc) : Lemma
(requires (modifies s2 h h' /\ loc_includes s1 s2))
(ensures (modifies s1 h h')) | val modifies_loc_includes (s1:loc) (h h':vale_heap) (s2:loc) : Lemma
(requires (modifies s2 h h' /\ loc_includes s1 s2))
(ensures (modifies s1 h h')) | let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 243,
"start_col": 0,
"start_line": 243
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: Vale.PPC64LE.Memory.loc ->
h: Vale.Arch.HeapImpl.vale_heap ->
h': Vale.Arch.HeapImpl.vale_heap ->
s2: Vale.PPC64LE.Memory.loc
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.modifies s2 h h' /\ Vale.PPC64LE.Memory.loc_includes s1 s2)
(ensures Vale.PPC64LE.Memory.modifies s1 h h') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"LowStar.Monotonic.Buffer.modifies_loc_includes",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Prims.unit"
] | [] | true | false | true | false | false | let modifies_loc_includes s1 h h' s2 =
| M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.load_felem | val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i])) | val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i])) | let load_felem #w f lo hi =
let (f0, f1, f2, f3, f4) = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4 | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 439,
"start_col": 0,
"start_line": 432
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul)))
let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
inline_for_extraction noextract
val fmul_rn:
#w:lanes
-> out:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h p /\
(let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h rn (2,2,2,2,2) /\
felem_fits h rn_5 (10,10,10,10,10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn)))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 Vec.pfmul (feval h0 f1) (feval h0 (gsub p 10ul 5ul)))
let fmul_rn #w out f1 p =
let rn = sub p 10ul 5ul in
let rn5 = sub p 15ul 5ul in
fmul_r #w out f1 rn rn5
inline_for_extraction noextract
val reduce_felem:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\ felem_fits h f (2,2,2,2,2))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #w f =
let f0 = f.(0ul) in
let f1 = f.(1ul) in
let f2 = f.(2ul) in
let f3 = f.(3ul) in
let f4 = f.(4ul) in
let (f0, f1, f2, f3, f4) =
reduce_felem5 (f0, f1, f2, f3, f4) in
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
inline_for_extraction noextract
val precompute_shift_reduce:
#w:lanes
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h -> live h f1 /\ live h f2)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
as_tup5 h1 f1 == precomp_r5 (as_tup5 h0 f2))
let precompute_shift_reduce #w f1 f2 =
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
f1.(0ul) <- vec_smul_mod f20 (u64 5);
f1.(1ul) <- vec_smul_mod f21 (u64 5);
f1.(2ul) <- vec_smul_mod f22 (u64 5);
f1.(3ul) <- vec_smul_mod f23 (u64 5);
f1.(4ul) <- vec_smul_mod f24 (u64 5)
inline_for_extraction noextract
val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: Hacl.Impl.Poly1305.Field32xN.felem w ->
lo: Hacl.Spec.Poly1305.Field32xN.uint64xN w ->
hi: Hacl.Spec.Poly1305.Field32xN.uint64xN w
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.felem",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.Buffer.op_Array_Assignment",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.load_felem5_lemma",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.load_felem5"
] | [] | false | true | false | false | false | let load_felem #w f lo hi =
| let f0, f1, f2, f3, f4 = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_goal_directed_trans2 | val modifies_goal_directed_trans2 (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma
(requires
modifies s12 h1 h2 /\
modifies_goal_directed s13 h2 h3 /\
loc_includes s13 s12
)
(ensures (modifies_goal_directed s13 h1 h3))
[SMTPat (modifies s12 h1 h2); SMTPat (modifies_goal_directed s13 h1 h3)] | val modifies_goal_directed_trans2 (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma
(requires
modifies s12 h1 h2 /\
modifies_goal_directed s13 h2 h3 /\
loc_includes s13 s12
)
(ensures (modifies_goal_directed s13 h1 h3))
[SMTPat (modifies s12 h1 h2); SMTPat (modifies_goal_directed s13 h1 h3)] | let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 251,
"start_col": 0,
"start_line": 251
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s12: Vale.PPC64LE.Memory.loc ->
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap ->
s13: Vale.PPC64LE.Memory.loc ->
h3: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
Vale.PPC64LE.Memory.modifies s12 h1 h2 /\
Vale.PPC64LE.Memory.modifies_goal_directed s13 h2 h3 /\
Vale.PPC64LE.Memory.loc_includes s13 s12)
(ensures Vale.PPC64LE.Memory.modifies_goal_directed s13 h1 h3)
[
SMTPat (Vale.PPC64LE.Memory.modifies s12 h1 h2);
SMTPat (Vale.PPC64LE.Memory.modifies_goal_directed s13 h1 h3)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.modifies_goal_directed_trans",
"Prims.unit"
] | [] | true | false | true | false | false | let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 =
| modifies_goal_directed_trans s12 h1 h2 s13 h3 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_goal_directed_trans | val modifies_goal_directed_trans (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma
(requires
modifies s12 h1 h2 /\
modifies_goal_directed s13 h2 h3 /\
loc_includes s13 s12
)
(ensures (modifies s13 h1 h3))
[SMTPat (modifies s12 h1 h2); SMTPat (modifies s13 h1 h3)] | val modifies_goal_directed_trans (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma
(requires
modifies s12 h1 h2 /\
modifies_goal_directed s13 h2 h3 /\
loc_includes s13 s12
)
(ensures (modifies s13 h1 h3))
[SMTPat (modifies s12 h1 h2); SMTPat (modifies s13 h1 h3)] | let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
() | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 249,
"start_col": 0,
"start_line": 246
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s12: Vale.PPC64LE.Memory.loc ->
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap ->
s13: Vale.PPC64LE.Memory.loc ->
h3: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
Vale.PPC64LE.Memory.modifies s12 h1 h2 /\
Vale.PPC64LE.Memory.modifies_goal_directed s13 h2 h3 /\
Vale.PPC64LE.Memory.loc_includes s13 s12)
(ensures Vale.PPC64LE.Memory.modifies s13 h1 h3)
[
SMTPat (Vale.PPC64LE.Memory.modifies s12 h1 h2);
SMTPat (Vale.PPC64LE.Memory.modifies s13 h1 h3)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.unit",
"Vale.PPC64LE.Memory.modifies_loc_includes",
"Vale.PPC64LE.Memory.loc_union",
"Vale.PPC64LE.Memory.modifies_trans"
] | [] | true | false | true | false | false | let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
| modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
() | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.load_felems_le | val load_felems_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 (size w *! 16ul)
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem (as_seq h0 b)) | val load_felems_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 (size w *! 16ul)
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem (as_seq h0 b)) | let load_felems_le #w f b =
match w with
| 1 -> load_felem1_le f b
| 2 -> load_felem2_le f b
| 4 -> load_felem4_le f b | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 659,
"start_col": 0,
"start_line": 655
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul)))
let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
inline_for_extraction noextract
val fmul_rn:
#w:lanes
-> out:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h p /\
(let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h rn (2,2,2,2,2) /\
felem_fits h rn_5 (10,10,10,10,10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn)))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 Vec.pfmul (feval h0 f1) (feval h0 (gsub p 10ul 5ul)))
let fmul_rn #w out f1 p =
let rn = sub p 10ul 5ul in
let rn5 = sub p 15ul 5ul in
fmul_r #w out f1 rn rn5
inline_for_extraction noextract
val reduce_felem:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\ felem_fits h f (2,2,2,2,2))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #w f =
let f0 = f.(0ul) in
let f1 = f.(1ul) in
let f2 = f.(2ul) in
let f3 = f.(3ul) in
let f4 = f.(4ul) in
let (f0, f1, f2, f3, f4) =
reduce_felem5 (f0, f1, f2, f3, f4) in
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
inline_for_extraction noextract
val precompute_shift_reduce:
#w:lanes
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h -> live h f1 /\ live h f2)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
as_tup5 h1 f1 == precomp_r5 (as_tup5 h0 f2))
let precompute_shift_reduce #w f1 f2 =
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
f1.(0ul) <- vec_smul_mod f20 (u64 5);
f1.(1ul) <- vec_smul_mod f21 (u64 5);
f1.(2ul) <- vec_smul_mod f22 (u64 5);
f1.(3ul) <- vec_smul_mod f23 (u64 5);
f1.(4ul) <- vec_smul_mod f24 (u64 5)
inline_for_extraction noextract
val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i]))
let load_felem #w f lo hi =
let (f0, f1, f2, f3, f4) = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
#push-options "--max_fuel 2"
inline_for_extraction noextract
val load_precompute_r1:
p:precomp_r 1
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r1 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 1 in
let r_vec1 = vec_load r1 1 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 1 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
copy_felem #_ #(1,1,1,1,1) rn r;
copy_felem #_ #(5,5,5,5,5) rn_5 r5
inline_for_extraction noextract
val load_precompute_r2:
p:precomp_r 2
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r2 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 2 in
let r_vec1 = vec_load r1 2 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 2 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
let h2 = ST.get () in
fmul_r rn r r r5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h2 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r4:
p:precomp_r 4
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r4 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 4 in
let r_vec1 = vec_load r1 4 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 4 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
fmul_r rn r r r5;
precompute_shift_reduce rn_5 rn;
fmul_r rn rn rn rn_5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h1 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create w (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r #w p r0 r1 =
match w with
| 1 -> load_precompute_r1 p r0 r1
| 2 -> load_precompute_r2 p r0 r1
| 4 -> load_precompute_r4 p r0 r1
#pop-options
inline_for_extraction noextract
val load_felem1_le:
f:felem 1
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem1 (as_seq h0 b))
let load_felem1_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 1 (sub b 0ul 8ul) in
let hi = vec_load_le U64 1 (sub b 8ul 8ul) in
load_felem f lo hi;
let h1 = ST.get () in
uints_from_bytes_le_lemma64_1 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem1 (as_seq h0 b))
inline_for_extraction noextract
val load_felem2_le:
f:felem 2
-> b:lbuffer uint8 32ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem2 (as_seq h0 b))
let load_felem2_le f b =
let h0 = ST.get () in
let b1 = vec_load_le U64 2 (sub b 0ul 16ul) in
let b2 = vec_load_le U64 2 (sub b 16ul 16ul) in
let lo = vec_interleave_low b1 b2 in
let hi = vec_interleave_high b1 b2 in
load_felem f lo hi;
let h1 = ST.get () in
vec_interleave_low_lemma2 b1 b2;
vec_interleave_high_lemma2 b1 b2;
uints_from_bytes_le_lemma64_2 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem2 (as_seq h0 b))
inline_for_extraction noextract
val load_felem4_le:
f:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem4 (as_seq h0 b))
let load_felem4_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 4 (sub b 0ul 32ul) in
let hi = vec_load_le U64 4 (sub b 32ul 32ul) in
let (o0, o1, o2, o3, o4) = load_felem5_4 lo hi in
load_felem5_le (as_seq h0 b);
f.(0ul) <- o0;
f.(1ul) <- o1;
f.(2ul) <- o2;
f.(3ul) <- o3;
f.(4ul) <- o4
inline_for_extraction noextract
val load_felems_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 (size w *! 16ul)
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: Hacl.Impl.Poly1305.Field32xN.felem w ->
b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Lib.IntTypes.size w *! 16ul)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.felem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Poly1305.Field32xN.load_felem1_le",
"Prims.unit",
"Hacl.Impl.Poly1305.Field32xN.load_felem2_le",
"Hacl.Impl.Poly1305.Field32xN.load_felem4_le"
] | [] | false | true | false | false | false | let load_felems_le #w f b =
| match w with
| 1 -> load_felem1_le f b
| 2 -> load_felem2_le f b
| 4 -> load_felem4_le f b | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.load_felem4_le | val load_felem4_le:
f:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem4 (as_seq h0 b)) | val load_felem4_le:
f:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem4 (as_seq h0 b)) | let load_felem4_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 4 (sub b 0ul 32ul) in
let hi = vec_load_le U64 4 (sub b 32ul 32ul) in
let (o0, o1, o2, o3, o4) = load_felem5_4 lo hi in
load_felem5_le (as_seq h0 b);
f.(0ul) <- o0;
f.(1ul) <- o1;
f.(2ul) <- o2;
f.(3ul) <- o3;
f.(4ul) <- o4 | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 640,
"start_col": 0,
"start_line": 630
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul)))
let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
inline_for_extraction noextract
val fmul_rn:
#w:lanes
-> out:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h p /\
(let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h rn (2,2,2,2,2) /\
felem_fits h rn_5 (10,10,10,10,10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn)))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 Vec.pfmul (feval h0 f1) (feval h0 (gsub p 10ul 5ul)))
let fmul_rn #w out f1 p =
let rn = sub p 10ul 5ul in
let rn5 = sub p 15ul 5ul in
fmul_r #w out f1 rn rn5
inline_for_extraction noextract
val reduce_felem:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\ felem_fits h f (2,2,2,2,2))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #w f =
let f0 = f.(0ul) in
let f1 = f.(1ul) in
let f2 = f.(2ul) in
let f3 = f.(3ul) in
let f4 = f.(4ul) in
let (f0, f1, f2, f3, f4) =
reduce_felem5 (f0, f1, f2, f3, f4) in
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
inline_for_extraction noextract
val precompute_shift_reduce:
#w:lanes
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h -> live h f1 /\ live h f2)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
as_tup5 h1 f1 == precomp_r5 (as_tup5 h0 f2))
let precompute_shift_reduce #w f1 f2 =
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
f1.(0ul) <- vec_smul_mod f20 (u64 5);
f1.(1ul) <- vec_smul_mod f21 (u64 5);
f1.(2ul) <- vec_smul_mod f22 (u64 5);
f1.(3ul) <- vec_smul_mod f23 (u64 5);
f1.(4ul) <- vec_smul_mod f24 (u64 5)
inline_for_extraction noextract
val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i]))
let load_felem #w f lo hi =
let (f0, f1, f2, f3, f4) = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
#push-options "--max_fuel 2"
inline_for_extraction noextract
val load_precompute_r1:
p:precomp_r 1
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r1 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 1 in
let r_vec1 = vec_load r1 1 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 1 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
copy_felem #_ #(1,1,1,1,1) rn r;
copy_felem #_ #(5,5,5,5,5) rn_5 r5
inline_for_extraction noextract
val load_precompute_r2:
p:precomp_r 2
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r2 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 2 in
let r_vec1 = vec_load r1 2 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 2 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
let h2 = ST.get () in
fmul_r rn r r r5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h2 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r4:
p:precomp_r 4
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r4 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 4 in
let r_vec1 = vec_load r1 4 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 4 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
fmul_r rn r r r5;
precompute_shift_reduce rn_5 rn;
fmul_r rn rn rn rn_5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h1 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create w (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r #w p r0 r1 =
match w with
| 1 -> load_precompute_r1 p r0 r1
| 2 -> load_precompute_r2 p r0 r1
| 4 -> load_precompute_r4 p r0 r1
#pop-options
inline_for_extraction noextract
val load_felem1_le:
f:felem 1
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem1 (as_seq h0 b))
let load_felem1_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 1 (sub b 0ul 8ul) in
let hi = vec_load_le U64 1 (sub b 8ul 8ul) in
load_felem f lo hi;
let h1 = ST.get () in
uints_from_bytes_le_lemma64_1 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem1 (as_seq h0 b))
inline_for_extraction noextract
val load_felem2_le:
f:felem 2
-> b:lbuffer uint8 32ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem2 (as_seq h0 b))
let load_felem2_le f b =
let h0 = ST.get () in
let b1 = vec_load_le U64 2 (sub b 0ul 16ul) in
let b2 = vec_load_le U64 2 (sub b 16ul 16ul) in
let lo = vec_interleave_low b1 b2 in
let hi = vec_interleave_high b1 b2 in
load_felem f lo hi;
let h1 = ST.get () in
vec_interleave_low_lemma2 b1 b2;
vec_interleave_high_lemma2 b1 b2;
uints_from_bytes_le_lemma64_2 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem2 (as_seq h0 b))
inline_for_extraction noextract
val load_felem4_le:
f:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.Impl.Poly1305.Field32xN.felem 4 -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Poly1305.Field32xN.felem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.Buffer.op_Array_Assignment",
"Prims.unit",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.load_felem5_le",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.load_felem5_4",
"Lib.IntVector.vec_t",
"Lib.IntTypes.U64",
"Lib.IntVector.vec_load_le",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mul",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.mk_int",
"Lib.Buffer.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let load_felem4_le f b =
| let h0 = ST.get () in
let lo = vec_load_le U64 4 (sub b 0ul 32ul) in
let hi = vec_load_le U64 4 (sub b 32ul 32ul) in
let o0, o1, o2, o3, o4 = load_felem5_4 lo hi in
load_felem5_le (as_seq h0 b);
f.(0ul) <- o0;
f.(1ul) <- o1;
f.(2ul) <- o2;
f.(3ul) <- o3;
f.(4ul) <- o4 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.writeable_mem64 | val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool | val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool | let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 410,
"start_col": 0,
"start_line": 410
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.writeable_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.bool"
] | [] | false | false | false | false | false | let writeable_mem64 ptr h =
| writeable_mem (TUInt64) ptr h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.buffer_read | val buffer_read (#t:base_typ) (b:buffer t) (i:int) (h:vale_heap) : Ghost (base_typ_as_vale_type t)
(requires True)
(ensures (fun v ->
0 <= i /\ i < buffer_length b /\ buffer_readable h b ==>
v == Seq.index (buffer_as_seq h b) i
)) | val buffer_read (#t:base_typ) (b:buffer t) (i:int) (h:vale_heap) : Ghost (base_typ_as_vale_type t)
(requires True)
(ensures (fun v ->
0 <= i /\ i < buffer_length b /\ buffer_readable h b ==>
v == Seq.index (buffer_as_seq h b) i
)) | let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 264,
"start_col": 0,
"start_line": 262
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.PPC64LE.Memory.buffer t -> i: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost (Vale.PPC64LE.Memory.base_typ_as_vale_type t) | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_BarBar",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"Vale.PPC64LE.Memory.buffer_length",
"Vale.PPC64LE.Memory.default_of_typ",
"Prims.bool",
"FStar.Seq.Base.index",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"Vale.PPC64LE.Memory.buffer_as_seq"
] | [] | false | false | false | false | false | let buffer_read #t b i h =
| if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.default_of_typ | val default_of_typ (t: base_typ) : base_typ_as_vale_type t | val default_of_typ (t: base_typ) : base_typ_as_vale_type t | let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 260,
"start_col": 0,
"start_line": 253
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> Vale.PPC64LE.Memory.base_typ_as_vale_type t | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"Prims.unit",
"FStar.Pervasives.allow_inversion"
] | [] | false | false | false | false | false | let default_of_typ (t: base_typ) : base_typ_as_vale_type t =
| allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.load_mem64 | val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 | val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 | let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 436,
"start_col": 0,
"start_line": 434
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Vale.Def.Types_s.nat64 | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.PPC64LE.Memory.valid_mem64",
"Prims.bool",
"Vale.PPC64LE.Memory.load_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Def.Types_s.nat64"
] | [] | false | false | false | false | false | let load_mem64 ptr h =
| if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.store_mem64 | val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap | val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap | let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 475,
"start_col": 0,
"start_line": 473
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Vale.Arch.HeapImpl.vale_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.PPC64LE.Memory.valid_mem64",
"Prims.bool",
"Vale.PPC64LE.Memory.store_mem",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | false | false | false | false | false | let store_mem64 i v h =
| if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_trans | val modifies_trans (s12:loc) (h1 h2:vale_heap) (s23:loc) (h3:vale_heap) : Lemma
(requires (modifies s12 h1 h2 /\ modifies s23 h2 h3))
(ensures (modifies (loc_union s12 s23) h1 h3)) | val modifies_trans (s12:loc) (h1 h2:vale_heap) (s23:loc) (h3:vale_heap) : Lemma
(requires (modifies s12 h1 h2 /\ modifies s23 h2 h3))
(ensures (modifies (loc_union s12 s23) h1 h3)) | let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 244,
"start_col": 0,
"start_line": 244
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s12: Vale.PPC64LE.Memory.loc ->
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap ->
s23: Vale.PPC64LE.Memory.loc ->
h3: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.modifies s12 h1 h2 /\ Vale.PPC64LE.Memory.modifies s23 h2 h3)
(ensures Vale.PPC64LE.Memory.modifies (Vale.PPC64LE.Memory.loc_union s12 s23) h1 h3) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"LowStar.Monotonic.Buffer.modifies_trans",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Prims.unit"
] | [] | true | false | true | false | false | let modifies_trans s12 h1 h2 s23 h3 =
| M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.load_precompute_r | val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create w (uint_v r1 * pow2 64 + uint_v r0))) | val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create w (uint_v r1 * pow2 64 + uint_v r0))) | let load_precompute_r #w p r0 r1 =
match w with
| 1 -> load_precompute_r1 p r0 r1
| 2 -> load_precompute_r2 p r0 r1
| 4 -> load_precompute_r4 p r0 r1 | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 570,
"start_col": 0,
"start_line": 566
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul)))
let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
inline_for_extraction noextract
val fmul_rn:
#w:lanes
-> out:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h p /\
(let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h rn (2,2,2,2,2) /\
felem_fits h rn_5 (10,10,10,10,10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn)))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 Vec.pfmul (feval h0 f1) (feval h0 (gsub p 10ul 5ul)))
let fmul_rn #w out f1 p =
let rn = sub p 10ul 5ul in
let rn5 = sub p 15ul 5ul in
fmul_r #w out f1 rn rn5
inline_for_extraction noextract
val reduce_felem:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\ felem_fits h f (2,2,2,2,2))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #w f =
let f0 = f.(0ul) in
let f1 = f.(1ul) in
let f2 = f.(2ul) in
let f3 = f.(3ul) in
let f4 = f.(4ul) in
let (f0, f1, f2, f3, f4) =
reduce_felem5 (f0, f1, f2, f3, f4) in
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
inline_for_extraction noextract
val precompute_shift_reduce:
#w:lanes
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h -> live h f1 /\ live h f2)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
as_tup5 h1 f1 == precomp_r5 (as_tup5 h0 f2))
let precompute_shift_reduce #w f1 f2 =
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
f1.(0ul) <- vec_smul_mod f20 (u64 5);
f1.(1ul) <- vec_smul_mod f21 (u64 5);
f1.(2ul) <- vec_smul_mod f22 (u64 5);
f1.(3ul) <- vec_smul_mod f23 (u64 5);
f1.(4ul) <- vec_smul_mod f24 (u64 5)
inline_for_extraction noextract
val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i]))
let load_felem #w f lo hi =
let (f0, f1, f2, f3, f4) = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
#push-options "--max_fuel 2"
inline_for_extraction noextract
val load_precompute_r1:
p:precomp_r 1
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r1 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 1 in
let r_vec1 = vec_load r1 1 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 1 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
copy_felem #_ #(1,1,1,1,1) rn r;
copy_felem #_ #(5,5,5,5,5) rn_5 r5
inline_for_extraction noextract
val load_precompute_r2:
p:precomp_r 2
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r2 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 2 in
let r_vec1 = vec_load r1 2 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 2 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
let h2 = ST.get () in
fmul_r rn r r r5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h2 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r4:
p:precomp_r 4
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r4 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 4 in
let r_vec1 = vec_load r1 4 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 4 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
fmul_r rn r r r5;
precompute_shift_reduce rn_5 rn;
fmul_r rn rn rn rn_5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h1 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) == | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Hacl.Impl.Poly1305.Field32xN.precomp_r w -> r0: Lib.IntTypes.uint64 -> r1: Lib.IntTypes.uint64
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.precomp_r",
"Lib.IntTypes.uint64",
"Hacl.Impl.Poly1305.Field32xN.load_precompute_r1",
"Prims.unit",
"Hacl.Impl.Poly1305.Field32xN.load_precompute_r2",
"Hacl.Impl.Poly1305.Field32xN.load_precompute_r4"
] | [] | false | true | false | false | false | let load_precompute_r #w p r0 r1 =
| match w with
| 1 -> load_precompute_r1 p r0 r1
| 2 -> load_precompute_r2 p r0 r1
| 4 -> load_precompute_r4 p r0 r1 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.index64_heap_aux | val index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int)
: Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) | val index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int)
: Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) | let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal () | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 105,
"start_col": 0,
"start_line": 98
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Properties.lseq FStar.UInt8.t 8 ->
heap: Vale.Arch.MachineHeap_s.machine_heap ->
ptr: Prims.int
-> FStar.Pervasives.Lemma
(requires
forall (j: Prims.nat{j < 8}). FStar.UInt8.v (FStar.Seq.Base.index s j) == heap.[ ptr + j ])
(ensures
FStar.UInt64.v (Vale.Interop.Views.get64 s) ==
Vale.Arch.MachineHeap_s.get_heap_val64 ptr heap) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.int",
"Vale.Def.Types_s.le_bytes_to_nat64_reveal",
"Prims.unit",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Vale.Interop.Views.get64_reveal",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.nat8",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.four",
"Prims.op_Division",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt8.n",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Vale.Def.Words_s.pow2_8",
"FStar.UInt8.v",
"FStar.Seq.Base.index",
"Vale.PPC64LE.Memory.op_String_Access",
"Vale.Def.Types_s.nat8",
"Prims.op_Addition",
"Prims.squash",
"FStar.UInt64.n",
"Vale.Def.Words_s.pow2_64",
"FStar.UInt64.v",
"Vale.Interop.Views.get64",
"Vale.Arch.MachineHeap_s.get_heap_val64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int)
: Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
| let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal () | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.get_addr_in_ptr | val get_addr_in_ptr (t: base_typ) (n base addr i: nat)
: Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i]) | val get_addr_in_ptr (t: base_typ) (n base addr i: nat)
: Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i]) | let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 338,
"start_col": 0,
"start_line": 332
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
n: Prims.nat ->
base: Prims.nat ->
addr: Prims.nat ->
i: Prims.nat
-> Prims.Ghost Prims.nat | Prims.Ghost | [
""
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Vale.PPC64LE.Memory.scale_t",
"Prims.bool",
"Vale.PPC64LE.Memory.get_addr_in_ptr",
"Vale.PPC64LE.Memory.valid_offset",
"Prims.eq2"
] | [
"recursion"
] | false | false | false | false | false | let rec get_addr_in_ptr (t: base_typ) (n base addr i: nat)
: Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i]) =
| if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_buffer | val valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool | val valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool | let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 342,
"start_col": 0,
"start_line": 340
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
b: Vale.PPC64LE.Memory.b8 ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Interop.Types.view_n",
"Vale.PPC64LE.Memory.addr_in_ptr",
"Prims.bool"
] | [] | false | false | false | false | false | let valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool =
| DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.load_mem128 | val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32 | val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32 | let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 495,
"start_col": 0,
"start_line": 493
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Vale.Def.Types_s.quad32 | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.PPC64LE.Memory.valid_mem128",
"Vale.PPC64LE.Memory.default_of_typ",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.bool",
"Vale.PPC64LE.Memory.load_mem",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | false | false | let load_mem128 ptr h =
| if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.store_mem128 | val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap | val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap | let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 498,
"start_col": 0,
"start_line": 496
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Vale.Arch.HeapImpl.vale_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.PPC64LE.Memory.valid_mem128",
"Prims.bool",
"Vale.PPC64LE.Memory.store_mem",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | false | false | false | false | false | let store_mem128 ptr v h =
| if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.load_felem2_le | val load_felem2_le:
f:felem 2
-> b:lbuffer uint8 32ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem2 (as_seq h0 b)) | val load_felem2_le:
f:felem 2
-> b:lbuffer uint8 32ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem2 (as_seq h0 b)) | let load_felem2_le f b =
let h0 = ST.get () in
let b1 = vec_load_le U64 2 (sub b 0ul 16ul) in
let b2 = vec_load_le U64 2 (sub b 16ul 16ul) in
let lo = vec_interleave_low b1 b2 in
let hi = vec_interleave_high b1 b2 in
load_felem f lo hi;
let h1 = ST.get () in
vec_interleave_low_lemma2 b1 b2;
vec_interleave_high_lemma2 b1 b2;
uints_from_bytes_le_lemma64_2 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem2 (as_seq h0 b)) | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 617,
"start_col": 0,
"start_line": 606
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul)))
let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
inline_for_extraction noextract
val fmul_rn:
#w:lanes
-> out:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h p /\
(let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h rn (2,2,2,2,2) /\
felem_fits h rn_5 (10,10,10,10,10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn)))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 Vec.pfmul (feval h0 f1) (feval h0 (gsub p 10ul 5ul)))
let fmul_rn #w out f1 p =
let rn = sub p 10ul 5ul in
let rn5 = sub p 15ul 5ul in
fmul_r #w out f1 rn rn5
inline_for_extraction noextract
val reduce_felem:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\ felem_fits h f (2,2,2,2,2))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #w f =
let f0 = f.(0ul) in
let f1 = f.(1ul) in
let f2 = f.(2ul) in
let f3 = f.(3ul) in
let f4 = f.(4ul) in
let (f0, f1, f2, f3, f4) =
reduce_felem5 (f0, f1, f2, f3, f4) in
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
inline_for_extraction noextract
val precompute_shift_reduce:
#w:lanes
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h -> live h f1 /\ live h f2)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
as_tup5 h1 f1 == precomp_r5 (as_tup5 h0 f2))
let precompute_shift_reduce #w f1 f2 =
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
f1.(0ul) <- vec_smul_mod f20 (u64 5);
f1.(1ul) <- vec_smul_mod f21 (u64 5);
f1.(2ul) <- vec_smul_mod f22 (u64 5);
f1.(3ul) <- vec_smul_mod f23 (u64 5);
f1.(4ul) <- vec_smul_mod f24 (u64 5)
inline_for_extraction noextract
val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i]))
let load_felem #w f lo hi =
let (f0, f1, f2, f3, f4) = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
#push-options "--max_fuel 2"
inline_for_extraction noextract
val load_precompute_r1:
p:precomp_r 1
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r1 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 1 in
let r_vec1 = vec_load r1 1 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 1 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
copy_felem #_ #(1,1,1,1,1) rn r;
copy_felem #_ #(5,5,5,5,5) rn_5 r5
inline_for_extraction noextract
val load_precompute_r2:
p:precomp_r 2
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r2 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 2 in
let r_vec1 = vec_load r1 2 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 2 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
let h2 = ST.get () in
fmul_r rn r r r5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h2 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r4:
p:precomp_r 4
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r4 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 4 in
let r_vec1 = vec_load r1 4 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 4 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
fmul_r rn r r r5;
precompute_shift_reduce rn_5 rn;
fmul_r rn rn rn rn_5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h1 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create w (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r #w p r0 r1 =
match w with
| 1 -> load_precompute_r1 p r0 r1
| 2 -> load_precompute_r2 p r0 r1
| 4 -> load_precompute_r4 p r0 r1
#pop-options
inline_for_extraction noextract
val load_felem1_le:
f:felem 1
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem1 (as_seq h0 b))
let load_felem1_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 1 (sub b 0ul 8ul) in
let hi = vec_load_le U64 1 (sub b 8ul 8ul) in
load_felem f lo hi;
let h1 = ST.get () in
uints_from_bytes_le_lemma64_1 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem1 (as_seq h0 b))
inline_for_extraction noextract
val load_felem2_le:
f:felem 2
-> b:lbuffer uint8 32ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.Impl.Poly1305.Field32xN.felem 2 -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Poly1305.Field32xN.felem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.Sequence.eq_intro",
"Hacl.Spec.Poly1305.Vec.pfelem",
"Hacl.Impl.Poly1305.Field32xN.feval",
"Hacl.Spec.Poly1305.Vec.load_elem2",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Hacl.Impl.Poly1305.Lemmas.uints_from_bytes_le_lemma64_2",
"Lib.IntVector.vec_interleave_high_lemma2",
"Lib.IntTypes.U64",
"Lib.IntVector.vec_interleave_low_lemma2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Poly1305.Field32xN.load_felem",
"Lib.IntVector.vec_t",
"Lib.IntVector.vec_interleave_high",
"Lib.IntVector.vec_interleave_low",
"Lib.IntVector.vec_load_le",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mul",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.mk_int",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let load_felem2_le f b =
| let h0 = ST.get () in
let b1 = vec_load_le U64 2 (sub b 0ul 16ul) in
let b2 = vec_load_le U64 2 (sub b 16ul 16ul) in
let lo = vec_interleave_low b1 b2 in
let hi = vec_interleave_high b1 b2 in
load_felem f lo hi;
let h1 = ST.get () in
vec_interleave_low_lemma2 b1 b2;
vec_interleave_high_lemma2 b1 b2;
uints_from_bytes_le_lemma64_2 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem2 (as_seq h0 b)) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.seq_upd | val seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b)
: Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) | val seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b)
: Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) | let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 291,
"start_col": 0,
"start_line": 266
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
vb: LowStar.BufferView.Up.buffer b {LowStar.BufferView.Up.live h vb} ->
i: Prims.nat{i < LowStar.BufferView.Up.length vb} ->
x: b
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (FStar.Seq.Base.upd (LowStar.BufferView.Up.as_seq h vb) i x)
(LowStar.BufferView.Up.as_seq (LowStar.BufferView.Up.upd h vb i x) vb)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.live",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.BufferView.Up.length",
"Prims.unit",
"Prims.op_Subtraction",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Prims.bool",
"Prims.op_Addition",
"LowStar.BufferView.Up.as_seq_sel",
"LowStar.BufferView.Up.upd",
"LowStar.BufferView.Up.sel_upd",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"FStar.Seq.Properties.lseq",
"LowStar.BufferView.Up.as_seq",
"Prims.l_True",
"FStar.Seq.Base.equal"
] | [] | false | false | true | false | false | let seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b)
: Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) =
| let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k: nat)
: Lemma
(requires
(k <= Seq.length upd_s /\
(forall (j: nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j: nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s
then ()
else
(UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k + 1))
in
aux 0 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_mem | val valid_mem : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 359,
"start_col": 0,
"start_line": 359
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.valid_mem_aux",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.bool"
] | [] | false | false | false | false | false | let valid_mem (t: base_typ) addr (h: vale_heap) =
| valid_mem_aux t addr (_ih h).ptrs h | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.buffer_write | val buffer_write (#t:base_typ) (b:buffer t) (i:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires buffer_readable h b /\ buffer_writeable b)
(ensures (fun h' ->
0 <= i /\ i < buffer_length b /\ buffer_readable h b ==>
modifies (loc_buffer b) h h' /\
get_heaplet_id h' == get_heaplet_id h /\
buffer_readable h' b /\
buffer_as_seq h' b == Seq.upd (buffer_as_seq h b) i v
)) | val buffer_write (#t:base_typ) (b:buffer t) (i:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires buffer_readable h b /\ buffer_writeable b)
(ensures (fun h' ->
0 <= i /\ i < buffer_length b /\ buffer_readable h b ==>
modifies (loc_buffer b) h h' /\
get_heaplet_id h' == get_heaplet_id h /\
buffer_readable h' b /\
buffer_as_seq h' b == Seq.upd (buffer_as_seq h b) i v
)) | let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 308,
"start_col": 0,
"start_line": 293
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer t ->
i: Prims.int ->
v: Vale.PPC64LE.Memory.base_typ_as_vale_type t ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost Vale.Arch.HeapImpl.vale_heap | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Prims.int",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_BarBar",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"Vale.PPC64LE.Memory.buffer_length",
"Prims.bool",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.PPC64LE.Memory.buffer_as_seq",
"FStar.Seq.Base.upd",
"Vale.PPC64LE.Memory.seq_upd",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Vale.PPC64LE.Memory.v_of_typ",
"Vale.Arch.HeapImpl.ValeHeap",
"FStar.Ghost.hide",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Interop.down_mem",
"Vale.Interop.Heap_s.InteropHeap",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"FStar.Monotonic.HyperStack.mem",
"LowStar.BufferView.Up.upd",
"LowStar.BufferView.Up.upd_equal_domains",
"LowStar.BufferView.Up.upd_modifies",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"LowStar.BufferView.Up.view",
"Prims.eq2",
"Prims.pos",
"LowStar.BufferView.Up.__proj__View__item__n",
"Vale.Interop.Types.view_n",
"Vale.PPC64LE.Memory.uint_view"
] | [] | false | false | false | false | false | let buffer_write #t b i v h =
| if i < 0 || i >= buffer_length b
then h
else
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h' | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.load_felem_le | val load_felem_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.create w (BSeq.nat_from_bytes_le (as_seq h0 b))) | val load_felem_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.create w (BSeq.nat_from_bytes_le (as_seq h0 b))) | let load_felem_le #w f b =
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
let f0 = vec_load lo w in
let f1 = vec_load hi w in
let h0 = ST.get () in
load_felem f f0 f1;
let h1 = ST.get () in
uint_from_bytes_le_lemma (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (LSeq.create w (BSeq.nat_from_bytes_le (as_seq h0 b))) | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 698,
"start_col": 0,
"start_line": 689
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul)))
let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
inline_for_extraction noextract
val fmul_rn:
#w:lanes
-> out:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h p /\
(let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h rn (2,2,2,2,2) /\
felem_fits h rn_5 (10,10,10,10,10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn)))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 Vec.pfmul (feval h0 f1) (feval h0 (gsub p 10ul 5ul)))
let fmul_rn #w out f1 p =
let rn = sub p 10ul 5ul in
let rn5 = sub p 15ul 5ul in
fmul_r #w out f1 rn rn5
inline_for_extraction noextract
val reduce_felem:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\ felem_fits h f (2,2,2,2,2))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(fas_nat h1 f).[0] == (feval h0 f).[0])
let reduce_felem #w f =
let f0 = f.(0ul) in
let f1 = f.(1ul) in
let f2 = f.(2ul) in
let f3 = f.(3ul) in
let f4 = f.(4ul) in
let (f0, f1, f2, f3, f4) =
reduce_felem5 (f0, f1, f2, f3, f4) in
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
inline_for_extraction noextract
val precompute_shift_reduce:
#w:lanes
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h -> live h f1 /\ live h f2)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
as_tup5 h1 f1 == precomp_r5 (as_tup5 h0 f2))
let precompute_shift_reduce #w f1 f2 =
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
f1.(0ul) <- vec_smul_mod f20 (u64 5);
f1.(1ul) <- vec_smul_mod f21 (u64 5);
f1.(2ul) <- vec_smul_mod f22 (u64 5);
f1.(3ul) <- vec_smul_mod f23 (u64 5);
f1.(4ul) <- vec_smul_mod f24 (u64 5)
inline_for_extraction noextract
val load_felem:
#w:lanes
-> f:felem w
-> lo:uint64xN w
-> hi:uint64xN w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == LSeq.createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i]))
let load_felem #w f lo hi =
let (f0, f1, f2, f3, f4) = load_felem5 #w lo hi in
load_felem5_lemma #w lo hi;
f.(0ul) <- f0;
f.(1ul) <- f1;
f.(2ul) <- f2;
f.(3ul) <- f3;
f.(4ul) <- f4
#push-options "--max_fuel 2"
inline_for_extraction noextract
val load_precompute_r1:
p:precomp_r 1
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r1 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 1 in
let r_vec1 = vec_load r1 1 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 1 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 1 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
copy_felem #_ #(1,1,1,1,1) rn r;
copy_felem #_ #(5,5,5,5,5) rn_5 r5
inline_for_extraction noextract
val load_precompute_r2:
p:precomp_r 2
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r2 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 2 in
let r_vec1 = vec_load r1 2 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 2 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 2 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
let h2 = ST.get () in
fmul_r rn r r r5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h2 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r4:
p:precomp_r 4
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r4 p r0 r1 =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let rn = sub p 10ul 5ul in
let rn_5 = sub p 15ul 5ul in
let r_vec0 = vec_load r0 4 in
let r_vec1 = vec_load r1 4 in
let h0 = ST.get () in
load_felem r r_vec0 r_vec1;
let h1 = ST.get () in
LSeq.eq_intro
(LSeq.createi #Vec.pfelem 4 (fun i -> (uint64xN_v r_vec1).[i] * pow2 64 + (uint64xN_v r_vec0).[i]))
(LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
assert (feval h1 r == LSeq.create 4 (uint_v r1 * pow2 64 + uint_v r0));
precompute_shift_reduce r5 r;
fmul_r rn r r r5;
precompute_shift_reduce rn_5 rn;
fmul_r rn rn rn rn_5;
let h3 = ST.get () in
LSeq.eq_intro (feval h3 rn) (Vec.compute_rw (feval h1 r).[0]);
precompute_shift_reduce rn_5 rn
inline_for_extraction noextract
val load_precompute_r:
#w:lanes
-> p:precomp_r w
-> r0:uint64
-> r1:uint64
-> Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
load_precompute_r_post #w h1 p /\
(assert_norm (pow2 64 * pow2 64 = pow2 128);
feval h1 (gsub p 0ul 5ul) ==
LSeq.create w (uint_v r1 * pow2 64 + uint_v r0)))
let load_precompute_r #w p r0 r1 =
match w with
| 1 -> load_precompute_r1 p r0 r1
| 2 -> load_precompute_r2 p r0 r1
| 4 -> load_precompute_r4 p r0 r1
#pop-options
inline_for_extraction noextract
val load_felem1_le:
f:felem 1
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem1 (as_seq h0 b))
let load_felem1_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 1 (sub b 0ul 8ul) in
let hi = vec_load_le U64 1 (sub b 8ul 8ul) in
load_felem f lo hi;
let h1 = ST.get () in
uints_from_bytes_le_lemma64_1 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem1 (as_seq h0 b))
inline_for_extraction noextract
val load_felem2_le:
f:felem 2
-> b:lbuffer uint8 32ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem2 (as_seq h0 b))
let load_felem2_le f b =
let h0 = ST.get () in
let b1 = vec_load_le U64 2 (sub b 0ul 16ul) in
let b2 = vec_load_le U64 2 (sub b 16ul 16ul) in
let lo = vec_interleave_low b1 b2 in
let hi = vec_interleave_high b1 b2 in
load_felem f lo hi;
let h1 = ST.get () in
vec_interleave_low_lemma2 b1 b2;
vec_interleave_high_lemma2 b1 b2;
uints_from_bytes_le_lemma64_2 (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (Vec.load_elem2 (as_seq h0 b))
inline_for_extraction noextract
val load_felem4_le:
f:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem4 (as_seq h0 b))
let load_felem4_le f b =
let h0 = ST.get () in
let lo = vec_load_le U64 4 (sub b 0ul 32ul) in
let hi = vec_load_le U64 4 (sub b 32ul 32ul) in
let (o0, o1, o2, o3, o4) = load_felem5_4 lo hi in
load_felem5_le (as_seq h0 b);
f.(0ul) <- o0;
f.(1ul) <- o1;
f.(2ul) <- o2;
f.(3ul) <- o3;
f.(4ul) <- o4
inline_for_extraction noextract
val load_felems_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 (size w *! 16ul)
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\
feval h1 f == Vec.load_elem (as_seq h0 b))
let load_felems_le #w f b =
match w with
| 1 -> load_felem1_le f b
| 2 -> load_felem2_le f b
| 4 -> load_felem4_le f b
inline_for_extraction noextract
val load_blocks:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 (size w *! 16ul)
-> Stack unit
(requires fun h ->
live h b /\ live h f /\ disjoint b f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == Vec.load_blocks #w (as_seq h0 b))
let load_blocks #s f b =
load_felems_le f b;
set_bit128 f
inline_for_extraction noextract
val load_felem_le:
#w:lanes
-> f:felem w
-> b:lbuffer uint8 16ul
-> Stack unit
(requires fun h -> live h f /\ live h b)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
felem_less h1 f (pow2 128) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.Impl.Poly1305.Field32xN.felem w -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.felem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.Sequence.eq_intro",
"Hacl.Spec.Poly1305.Vec.pfelem",
"Hacl.Impl.Poly1305.Field32xN.feval",
"Lib.Sequence.create",
"Lib.ByteSequence.nat_from_bytes_le",
"Lib.IntTypes.SEC",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Hacl.Impl.Poly1305.Lemmas.uint_from_bytes_le_lemma",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Poly1305.Field32xN.load_felem",
"Lib.IntVector.vec_t",
"Lib.IntTypes.U64",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntVector.vec_v",
"Lib.IntVector.vec_load",
"Lib.ByteBuffer.uint_from_bytes_le",
"Lib.IntTypes.uint_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let load_felem_le #w f b =
| let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
let f0 = vec_load lo w in
let f1 = vec_load hi w in
let h0 = ST.get () in
load_felem f f0 f1;
let h1 = ST.get () in
uint_from_bytes_le_lemma (as_seq h0 b);
LSeq.eq_intro (feval h1 f) (LSeq.create w (BSeq.nat_from_bytes_le (as_seq h0 b))) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_taint_b8 | val valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | val valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 565,
"start_col": 0,
"start_line": 562
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.b8 ->
h: Vale.Arch.HeapImpl.vale_heap ->
mt: Vale.PPC64LE.Memory.memtaint ->
tn: Vale.Arch.HeapTypes_s.taint
-> Prims.GTot Vale.Def.Prop_s.prop0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Vale.Arch.HeapTypes_s.taint",
"Prims.l_Forall",
"Prims.int",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.eq2",
"Vale.PPC64LE.Memory.op_String_Access",
"Vale.Def.Words_s.nat64",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Vale.Arch.HeapImpl._ih",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | false | false | let valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 =
| let addr = (_ih h).addrs b in
(forall (i: int). {:pattern (mt.[ i ])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[ i ] == tn) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_taint_bufs | val valid_taint_bufs : mem: Vale.Arch.HeapImpl.vale_heap ->
memTaint: Vale.PPC64LE.Memory.memtaint ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
ts: (_: Vale.PPC64LE.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint)
-> Prims.logical | let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 635,
"start_col": 0,
"start_line": 634
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
mem: Vale.Arch.HeapImpl.vale_heap ->
memTaint: Vale.PPC64LE.Memory.memtaint ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
ts: (_: Vale.PPC64LE.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint)
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapTypes_s.taint",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.List.Tot.Base.memP",
"Vale.PPC64LE.Memory.valid_taint_b8",
"Prims.logical"
] | [] | false | false | false | false | true | let valid_taint_bufs (mem: vale_heap) (memTaint: memtaint) (ps: list b8) (ts: (b8 -> GTot taint)) =
| forall b. {:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.same_memTaint128 | val same_memTaint128
(b:buffer128)
(mem0:vale_heap)
(mem1:vale_heap)
(memtaint0:memtaint)
(memtaint1:memtaint)
: Lemma
(requires (modifies (loc_buffer b) mem0 mem1 /\
(forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p)))
(ensures memtaint0 == memtaint1) | val same_memTaint128
(b:buffer128)
(mem0:vale_heap)
(mem1:vale_heap)
(memtaint0:memtaint)
(memtaint1:memtaint)
: Lemma
(requires (modifies (loc_buffer b) mem0 mem1 /\
(forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p)))
(ensures memtaint0 == memtaint1) | let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 610,
"start_col": 0,
"start_line": 609
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer128 ->
mem0: Vale.Arch.HeapImpl.vale_heap ->
mem1: Vale.Arch.HeapImpl.vale_heap ->
memtaint0: Vale.PPC64LE.Memory.memtaint ->
memtaint1: Vale.PPC64LE.Memory.memtaint
-> FStar.Pervasives.Lemma
(requires
Vale.PPC64LE.Memory.modifies (Vale.PPC64LE.Memory.loc_buffer b) mem0 mem1 /\
(forall (p: Prims.int). {:pattern FStar.Map.sel memtaint0 p\/FStar.Map.sel memtaint1 p}
FStar.Map.sel memtaint0 p == FStar.Map.sel memtaint1 p))
(ensures memtaint0 == memtaint1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Vale.PPC64LE.Memory.same_memTaint",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.unit"
] | [] | true | false | true | false | false | let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
| same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_taint_buf | val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 | val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 | let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 568,
"start_col": 0,
"start_line": 567
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer t ->
h: Vale.Arch.HeapImpl.vale_heap ->
mt: Vale.PPC64LE.Memory.memtaint ->
tn: Vale.Arch.HeapTypes_s.taint
-> Prims.GTot Vale.Def.Prop_s.prop0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.PPC64LE.Memory.valid_taint_b8",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | false | false | let valid_taint_buf #t b h mt tn =
| valid_taint_b8 b h mt tn | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.fmul_r | val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r)) | val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r)) | let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4 | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 290,
"start_col": 0,
"start_line": 264
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
out: Hacl.Impl.Poly1305.Field32xN.felem w ->
f1: Hacl.Impl.Poly1305.Field32xN.felem w ->
r: Hacl.Impl.Poly1305.Field32xN.felem w ->
r5: Hacl.Impl.Poly1305.Field32xN.felem w
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.felem",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.Buffer.op_Array_Assignment",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.fmul_r5",
"FStar.Pervasives.Native.Mktuple5",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT"
] | [] | false | true | false | false | false | let fmul_r #w out f1 r r5 =
| let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let o0, o1, o2, o3, o4 =
fmul_r5 #w (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54)
in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.same_memTaint64 | val same_memTaint64
(b:buffer64)
(mem0:vale_heap)
(mem1:vale_heap)
(memtaint0:memtaint)
(memtaint1:memtaint)
: Lemma
(requires (modifies (loc_buffer b) mem0 mem1 /\
(forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p)))
(ensures memtaint0 == memtaint1) | val same_memTaint64
(b:buffer64)
(mem0:vale_heap)
(mem1:vale_heap)
(memtaint0:memtaint)
(memtaint1:memtaint)
: Lemma
(requires (modifies (loc_buffer b) mem0 mem1 /\
(forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p)))
(ensures memtaint0 == memtaint1) | let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 607,
"start_col": 0,
"start_line": 606
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer64 ->
mem0: Vale.Arch.HeapImpl.vale_heap ->
mem1: Vale.Arch.HeapImpl.vale_heap ->
memtaint0: Vale.PPC64LE.Memory.memtaint ->
memtaint1: Vale.PPC64LE.Memory.memtaint
-> FStar.Pervasives.Lemma
(requires
Vale.PPC64LE.Memory.modifies (Vale.PPC64LE.Memory.loc_buffer b) mem0 mem1 /\
(forall (p: Prims.int). {:pattern FStar.Map.sel memtaint0 p\/FStar.Map.sel memtaint1 p}
FStar.Map.sel memtaint0 p == FStar.Map.sel memtaint1 p))
(ensures memtaint0 == memtaint1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.buffer64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Vale.PPC64LE.Memory.same_memTaint",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.unit"
] | [] | true | false | true | false | false | let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
| same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 | false |
LL.fst | LL.ewp_monotonic | val ewp_monotonic (#a: Type) (wp: ewp_t0 a) : Type0 | val ewp_monotonic (#a: Type) (wp: ewp_t0 a) : Type0 | let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 39,
"start_col": 0,
"start_line": 37
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | wp: LL.ewp_t0 a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"LL.ewp_t0",
"Prims.l_Forall",
"FStar.Pervasives.Native.option",
"Prims.logical",
"Prims.l_imp"
] | [] | false | false | false | true | true | let ewp_monotonic (#a: Type) (wp: ewp_t0 a) : Type0 =
| forall p q. (forall x. p x ==> q x) ==> (wp p ==> wp q) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.find_writeable_buffer | val find_writeable_buffer : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot (FStar.Pervasives.Native.option (Vale.PPC64LE.Memory.buffer t)) | let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 425,
"start_col": 0,
"start_line": 424
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot (FStar.Pervasives.Native.option (Vale.PPC64LE.Memory.buffer t)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.find_writeable_buffer_aux",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"FStar.Pervasives.Native.option",
"Vale.PPC64LE.Memory.buffer"
] | [] | false | false | false | false | false | let find_writeable_buffer (t: base_typ) (addr: int) (h: vale_heap) =
| find_writeable_buffer_aux t addr (_ih h).ptrs h | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.find_valid_buffer_ps | val find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap)
: Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) | val find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap)
: Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) | let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 387,
"start_col": 0,
"start_line": 383
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h1) ==
InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h2))
(ensures
Vale.PPC64LE.Memory.find_valid_buffer t addr h1 ==
Vale.PPC64LE.Memory.find_valid_buffer t addr h2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.find_valid_buffer_aux_ps",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.unit",
"Prims.eq2",
"Prims.list",
"Vale.Interop.Types.b8",
"Prims.l_or",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Prims.squash",
"FStar.Pervasives.Native.option",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.find_valid_buffer",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap)
: Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) =
| find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.writeable_mem | val writeable_mem : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 409,
"start_col": 0,
"start_line": 409
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.writeable_mem_aux",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.bool"
] | [] | false | false | false | false | false | let writeable_mem (t: base_typ) addr (h: vale_heap) =
| writeable_mem_aux t addr (_ih h).ptrs h | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.find_valid_buffer | val find_valid_buffer : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot (FStar.Pervasives.Native.option (Vale.PPC64LE.Memory.buffer t)) | let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 105,
"end_line": 373,
"start_col": 0,
"start_line": 373
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot (FStar.Pervasives.Native.option (Vale.PPC64LE.Memory.buffer t)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.find_valid_buffer_aux",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"FStar.Pervasives.Native.option",
"Vale.PPC64LE.Memory.buffer"
] | [] | false | false | false | false | false | let find_valid_buffer (t: base_typ) (addr: int) (h: vale_heap) =
| find_valid_buffer_aux t addr (_ih h).ptrs h | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_mem_aux | val valid_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap)
: Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures
fun b ->
b <==>
(exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h)) | val valid_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap)
: Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures
fun b ->
b <==>
(exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h)) | let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 358,
"start_col": 0,
"start_line": 350
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost Prims.bool | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_BarBar",
"Vale.PPC64LE.Memory.valid_buffer",
"Vale.PPC64LE.Memory.valid_mem_aux",
"Prims.bool",
"Vale.PPC64LE.Memory.sub_list",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.l_iff",
"Prims.b2t",
"Prims.l_Exists",
"Vale.PPC64LE.Memory.buffer",
"Prims.l_and",
"FStar.List.Tot.Base.memP"
] | [
"recursion"
] | false | false | false | false | false | let rec valid_mem_aux (t: base_typ) addr (ps: list b8) (h: vale_heap)
: Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures
fun b ->
b <==>
(exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h)) =
| match ps with
| [] -> false
| a :: q -> valid_buffer t addr a h || valid_mem_aux t addr q h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.layout_old_heap | val layout_old_heap (layout:vale_heap_layout_inner) : vale_heap | val layout_old_heap (layout:vale_heap_layout_inner) : vale_heap | let layout_old_heap layout = layout.vl_old_heap | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 754,
"start_col": 0,
"start_line": 754
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True
let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized
let mem_inv h =
h.vf_heap.heapletId == None /\
inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then
inv_heaplets h.vf_layout.vl_inner h.vf_heap
h.vf_heaplets h.vf_layout.vl_taint
else
h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> Vale.Arch.HeapImpl.vale_heap | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap",
"Vale.Arch.HeapImpl.vale_heap"
] | [] | false | false | false | true | false | let layout_old_heap layout =
| layout.vl_old_heap | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.is_initial_heap | val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0 | val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0 | let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 740,
"start_col": 0,
"start_line": 738
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout -> h: Vale.Arch.HeapImpl.vale_heap
-> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"Prims.eq2",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Prims.b2t",
"Prims.op_Negation",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | true | false | let is_initial_heap layout h =
| h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.length_t_eq | val length_t_eq (t: base_typ) (b: buffer t)
: Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) | val length_t_eq (t: base_typ) (b: buffer t)
: Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) | let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 444,
"start_col": 0,
"start_line": 438
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.PPC64LE.Memory.buffer t
-> FStar.Pervasives.Lemma
(ensures
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) ==
Vale.PPC64LE.Memory.buffer_length b * Vale.Interop.Types.view_n t) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"FStar.Math.Lib.lemma_div_def",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.view_n",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Vale.PPC64LE.Memory.buffer_length",
"Prims.op_Division",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"Vale.PPC64LE.Memory.uint_view",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.l_True",
"Prims.squash",
"FStar.Mul.op_Star",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_t_eq (t: base_typ) (b: buffer t)
: Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
| let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.mem_inv | val mem_inv (h:vale_full_heap) : prop0 | val mem_inv (h:vale_full_heap) : prop0 | let mem_inv h =
h.vf_heap.heapletId == None /\
inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then
inv_heaplets h.vf_layout.vl_inner h.vf_heap
h.vf_heaplets h.vf_layout.vl_taint
else
h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap
) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 751,
"start_col": 0,
"start_line": 742
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True
let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: Vale.Arch.HeapImpl.vale_full_heap -> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_full_heap",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"FStar.Pervasives.Native.None",
"Vale.PPC64LE.Memory.inv_heaplet_ids",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"Vale.PPC64LE.Memory.inv_heaplets",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Prims.bool",
"Vale.Arch.HeapImpl.vale_heaplets",
"Vale.Arch.HeapImpl.empty_vale_heaplets",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap",
"Prims.logical",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | true | false | let mem_inv h =
| h.vf_heap.heapletId == None /\ inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then inv_heaplets h.vf_layout.vl_inner h.vf_heap h.vf_heaplets h.vf_layout.vl_taint
else h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.inv_buffer_info | val inv_buffer_info : bi: Vale.Arch.HeapImpl.buffer_info ->
owners: (_: Vale.Arch.HeapImpl.heaplet_id -> FStar.Set.set Prims.int) ->
h: Vale.Arch.HeapImpl.vale_heap ->
hs: Vale.Arch.HeapImpl.vale_heaplets ->
mt: Vale.Arch.HeapTypes_s.memTaint_t ->
modloc: Vale.PPC64LE.Memory.loc
-> Prims.logical | let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 722,
"start_col": 0,
"start_line": 710
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bi: Vale.Arch.HeapImpl.buffer_info ->
owners: (_: Vale.Arch.HeapImpl.heaplet_id -> FStar.Set.set Prims.int) ->
h: Vale.Arch.HeapImpl.vale_heap ->
hs: Vale.Arch.HeapImpl.vale_heaplets ->
mt: Vale.Arch.HeapTypes_s.memTaint_t ->
modloc: Vale.PPC64LE.Memory.loc
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.buffer_info",
"Vale.Arch.HeapImpl.heaplet_id",
"FStar.Set.set",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.HeapImpl.vale_heaplets",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.PPC64LE.Memory.loc",
"Prims.l_and",
"Prims.l_imp",
"Prims.eq2",
"Vale.Arch.HeapImpl.mutability",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_mutable",
"Vale.Arch.HeapImpl.Mutable",
"Vale.PPC64LE.Memory.loc_includes",
"Vale.PPC64LE.Memory.loc_buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.PPC64LE.Memory.buffer_readable",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"Vale.PPC64LE.Memory.buffer_as_seq",
"Prims.l_iff",
"Vale.PPC64LE.Memory.valid_taint_buf",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_taint",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Vale.PPC64LE.Memory.buffer_addr",
"Prims.op_LessThan",
"Prims.op_Addition",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"FStar.Set.mem",
"Prims.l_True",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"Vale.Lib.Map16.get",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_buffer_info
(bi: buffer_info)
(owners: (heaplet_id -> Set.set int))
(h: vale_heap)
(hs: vale_heaplets)
(mt: memTaint_t)
(modloc: loc)
=
| let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i: int). {:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns
) /\ True | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.inv_heaplet_ids | val inv_heaplet_ids : hs: Vale.Arch.HeapImpl.vale_heaplets -> Prims.logical | let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 696,
"start_col": 0,
"start_line": 695
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | hs: Vale.Arch.HeapImpl.vale_heaplets -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heaplets",
"Prims.l_Forall",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId",
"Vale.Lib.Map16.sel",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Pervasives.Native.Some",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_heaplet_ids (hs: vale_heaplets) =
| forall (i: heaplet_id). {:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.store_mem | val store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap)
: Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) | val store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap)
: Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) | let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 471,
"start_col": 0,
"start_line": 463
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
v: Vale.PPC64LE.Memory.base_typ_as_vale_type t ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost Vale.Arch.HeapImpl.vale_heap | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.find_writeable_buffer",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.buffer_write",
"Vale.PPC64LE.Memory.get_addr_in_ptr",
"Vale.PPC64LE.Memory.buffer_length",
"Vale.PPC64LE.Memory.buffer_addr",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Vale.Interop.Types.addr_map",
"Prims.l_or",
"Vale.Interop.Heap_s.mk_addr_map",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Prims.list",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.list_disjoint_or_eq"
] | [] | false | false | false | false | false | let store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap)
: Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) =
| match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.layout_modifies_loc | val layout_modifies_loc (layout:vale_heap_layout_inner) : loc | val layout_modifies_loc (layout:vale_heap_layout_inner) : loc | let layout_modifies_loc layout = layout.vl_mod_loc | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 755,
"start_col": 0,
"start_line": 755
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True
let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized
let mem_inv h =
h.vf_heap.heapletId == None /\
inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then
inv_heaplets h.vf_layout.vl_inner h.vf_heap
h.vf_heaplets h.vf_layout.vl_taint
else
h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap
)
let layout_heaplets_initialized layout = layout.vl_heaplets_initialized | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> Vale.PPC64LE.Memory.loc | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_mod_loc",
"Vale.PPC64LE.Memory.loc"
] | [] | false | false | false | true | false | let layout_modifies_loc layout =
| layout.vl_mod_loc | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.get_addr_ptr | val get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap)
: Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) | val get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap)
: Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) | let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 450,
"start_col": 0,
"start_line": 446
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost (Vale.PPC64LE.Memory.buffer t) | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.find_valid_buffer",
"Prims.b2t",
"Vale.PPC64LE.Memory.valid_mem",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Vale.PPC64LE.Memory.valid_buffer"
] | [] | false | false | false | false | false | let get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap)
: Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) =
| Some?.v (find_valid_buffer t ptr h) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.find_writeable_buffer_aux | val find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap)
: Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures
fun o ->
(match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps)) | val find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap)
: Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures
fun o ->
(match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps)) | let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 422,
"start_col": 0,
"start_line": 412
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost (FStar.Pervasives.Native.option (Vale.PPC64LE.Memory.buffer t)) | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Pervasives.Native.None",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.writeable_buffer",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"Vale.PPC64LE.Memory.find_writeable_buffer_aux",
"FStar.Pervasives.Native.option",
"Vale.PPC64LE.Memory.sub_list",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.b2t",
"Prims.op_Negation",
"Vale.PPC64LE.Memory.writeable_mem_aux",
"Prims.l_and",
"FStar.List.Tot.Base.memP"
] | [
"recursion"
] | false | false | false | false | false | let rec find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap)
: Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures
fun o ->
(match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps)) =
| match ps with
| [] -> None
| a :: q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.layout_buffers | val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info | val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info | let layout_buffers layout = layout.vl_buffers | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 756,
"start_col": 0,
"start_line": 756
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True
let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized
let mem_inv h =
h.vf_heap.heapletId == None /\
inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then
inv_heaplets h.vf_layout.vl_inner h.vf_heap
h.vf_heaplets h.vf_layout.vl_taint
else
h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap
)
let layout_heaplets_initialized layout = layout.vl_heaplets_initialized
let layout_old_heap layout = layout.vl_old_heap | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner
-> FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info"
] | [] | false | false | false | true | false | let layout_buffers layout =
| layout.vl_buffers | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_mem128 | val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool | val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool | let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 491,
"start_col": 0,
"start_line": 491
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.valid_mem_aux",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.bool"
] | [] | false | false | false | false | false | let valid_mem128 ptr h =
| valid_mem_aux (TUInt128) ptr (_ih h).ptrs h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.writeable_mem128 | val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool | val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool | let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 492,
"start_col": 0,
"start_line": 492
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.writeable_mem_aux",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.bool"
] | [] | false | false | false | false | false | let writeable_mem128 ptr h =
| writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h | false |
LL.fst | LL.wpt_monotonic | val wpt_monotonic : wp: LL.wp_t0 a -> Prims.logical | let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 226,
"start_col": 0,
"start_line": 224
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | wp: LL.wp_t0 a -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LL.wp_t0",
"Prims.l_Forall",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Prims.logical",
"Prims.l_imp"
] | [] | false | false | false | true | true | let wpt_monotonic (#a: Type) (wp: wp_t0 a) =
| forall p q. (forall r. p r ==> q r) ==> (forall n. wp p n ==> wp q n) | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.writeable_mem_aux | val writeable_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap)
: Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures
fun b ->
b <==>
(exists (x: buffer t).
{:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) | val writeable_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap)
: Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures
fun b ->
b <==>
(exists (x: buffer t).
{:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) | let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 408,
"start_col": 0,
"start_line": 400
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost Prims.bool | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_BarBar",
"Vale.PPC64LE.Memory.writeable_buffer",
"Vale.PPC64LE.Memory.writeable_mem_aux",
"Prims.bool",
"Vale.PPC64LE.Memory.sub_list",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.l_iff",
"Prims.b2t",
"Prims.l_Exists",
"Vale.PPC64LE.Memory.buffer",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Vale.PPC64LE.Memory.valid_buffer",
"Vale.PPC64LE.Memory.buffer_writeable"
] | [
"recursion"
] | false | false | false | false | false | let rec writeable_mem_aux (t: base_typ) addr (ps: list b8) (h: vale_heap)
: Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures
fun b ->
b <==>
(exists (x: buffer t).
{:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) =
| match ps with
| [] -> false
| a :: q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h | false |
LL.fst | LL.esubcomp | val esubcomp (a: Type) (wp_f wp_g: ewp_t a) (f: erepr a wp_f)
: Pure (erepr a wp_g) (requires forall p. wp_g p ==> wp_f p) (ensures fun _ -> True) | val esubcomp (a: Type) (wp_f wp_g: ewp_t a) (f: erepr a wp_f)
: Pure (erepr a wp_g) (requires forall p. wp_g p ==> wp_f p) (ensures fun _ -> True) | let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 87,
"start_col": 0,
"start_line": 81
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> wp_f: LL.ewp_t a -> wp_g: LL.ewp_t a -> f: LL.erepr a wp_f
-> Prims.Pure (LL.erepr a wp_g) | Prims.Pure | [] | [] | [
"LL.ewp_t",
"LL.erepr",
"Prims.l_Forall",
"LL.epost_t",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let esubcomp (a: Type) (wp_f wp_g: ewp_t a) (f: erepr a wp_f)
: Pure (erepr a wp_g) (requires forall p. wp_g p ==> wp_f p) (ensures fun _ -> True) =
| f | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.layout_heaplets_initialized | val layout_heaplets_initialized (layout:vale_heap_layout_inner) : bool | val layout_heaplets_initialized (layout:vale_heap_layout_inner) : bool | let layout_heaplets_initialized layout = layout.vl_heaplets_initialized | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 753,
"start_col": 0,
"start_line": 753
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True
let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized
let mem_inv h =
h.vf_heap.heapletId == None /\
inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then
inv_heaplets h.vf_layout.vl_inner h.vf_heap
h.vf_heaplets h.vf_layout.vl_taint
else
h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized",
"Prims.bool"
] | [] | false | false | false | true | false | let layout_heaplets_initialized layout =
| layout.vl_heaplets_initialized | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.find_valid_buffer_aux | val find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap)
: Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures
fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps) | val find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap)
: Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures
fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps) | let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 371,
"start_col": 0,
"start_line": 362
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost (FStar.Pervasives.Native.option (Vale.PPC64LE.Memory.buffer t)) | Prims.Ghost | [] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Pervasives.Native.None",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.valid_buffer",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"Vale.PPC64LE.Memory.find_valid_buffer_aux",
"FStar.Pervasives.Native.option",
"Vale.PPC64LE.Memory.sub_list",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.b2t",
"Prims.op_Negation",
"Vale.PPC64LE.Memory.valid_mem_aux",
"Prims.l_and",
"FStar.List.Tot.Base.memP"
] | [
"recursion"
] | false | false | false | false | false | let rec find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap)
: Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures
fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps) =
| match ps with
| [] -> None
| a :: q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h | false |
LL.fst | LL.lift_pure_exn | val lift_pure_exn (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : erepr a (lift_pure_wp wp) | val lift_pure_exn (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : erepr a (lift_pure_wp wp) | let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ()) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 126,
"start_col": 0,
"start_line": 123
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> wp: Prims.pure_wp a -> f: (_: Prims.unit -> Prims.PURE a)
-> LL.erepr a (LL.lift_pure_wp wp) | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"Prims.unit",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.option",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"LL.erepr",
"LL.lift_pure_wp"
] | [] | false | false | false | false | false | let lift_pure_exn (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : erepr a (lift_pure_wp wp) =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ()) | false |
LL.fst | LL.lift_pure_wp | val lift_pure_wp (#a: Type) (wp: pure_wp a) : ewp_t a | val lift_pure_wp (#a: Type) (wp: pure_wp a) : ewp_t a | let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x)) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 120,
"start_col": 0,
"start_line": 118
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | wp: Prims.pure_wp a -> LL.ewp_t a | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"FStar.Pervasives.Native.option",
"Prims.l_True",
"FStar.Pervasives.Native.Some",
"Prims.pure_pre",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"LL.ewp_t"
] | [] | false | false | false | true | false | let lift_pure_wp (#a: Type) (wp: pure_wp a) : ewp_t a =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x)) | false |
LL.fst | LL.test_st | val test_st: Prims.unit -> Pure (option int) True (fun _ -> True) | val test_st: Prims.unit -> Pure (option int) True (fun _ -> True) | let test_st () : Pure (option int) True (fun _ -> True)
= reify (test ()) () | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 354,
"start_col": 0,
"start_line": 353
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n)))
inline_for_extraction
let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n)
sub_effect PURE ~> STEXN = lift_pure_stexn
effect StExn (a:Type) (pre:nat -> Type0) (post:nat -> option (a & nat) -> Type0) =
STEXN a (fun p n -> pre n /\ (forall r. post n r ==> p r))
(*** Example using the STEXN effect ***)
inline_for_extraction
let get_n1_stexn (_:unit)
: StExn nat
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= STEXN?.reflect (fun n -> get_n1_exn n)
/// get_flt function in the STEXN effect that hides the state also
inline_for_extraction
let get_flt_stexn (_:unit)
: StExn flt
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= let x = get_n1_stexn () in
let y = get_n1_stexn () in
let z = get_n1_stexn () in
{ n1 = x; n2 = y; n3 = z}
/// And now we can reify the effect to reveal a spec in terms of PURE
let get_flt_stexn_reified (n:nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= reify (reify (get_flt_stexn ()) n) ()
/// An extraction test
let test () : Exn int True (fun _ -> True)
= 4 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Prims.Pure (FStar.Pervasives.Native.option Prims.int) | Prims.Pure | [] | [] | [
"Prims.unit",
"LL.test",
"Prims.int",
"FStar.Pervasives.Native.option",
"Prims.l_True"
] | [] | false | false | false | false | false | let test_st () : Pure (option int) True (fun _ -> True) =
| reify (test ()) () | false |
LL.fst | LL.test | val test: Prims.unit -> Exn int True (fun _ -> True) | val test: Prims.unit -> Exn int True (fun _ -> True) | let test () : Exn int True (fun _ -> True)
= 4 | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 351,
"start_col": 0,
"start_line": 350
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n)))
inline_for_extraction
let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n)
sub_effect PURE ~> STEXN = lift_pure_stexn
effect StExn (a:Type) (pre:nat -> Type0) (post:nat -> option (a & nat) -> Type0) =
STEXN a (fun p n -> pre n /\ (forall r. post n r ==> p r))
(*** Example using the STEXN effect ***)
inline_for_extraction
let get_n1_stexn (_:unit)
: StExn nat
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= STEXN?.reflect (fun n -> get_n1_exn n)
/// get_flt function in the STEXN effect that hides the state also
inline_for_extraction
let get_flt_stexn (_:unit)
: StExn flt
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= let x = get_n1_stexn () in
let y = get_n1_stexn () in
let z = get_n1_stexn () in
{ n1 = x; n2 = y; n3 = z}
/// And now we can reify the effect to reveal a spec in terms of PURE
let get_flt_stexn_reified (n:nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= reify (reify (get_flt_stexn ()) n) ()
/// An extraction test | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> LL.Exn Prims.int | LL.Exn | [] | [] | [
"Prims.unit",
"Prims.int",
"Prims.l_True",
"FStar.Pervasives.Native.option"
] | [] | false | true | false | false | false | let test () : Exn int True (fun _ -> True) =
| 4 | false |
LL.fst | LL.ereturn | val ereturn (a: Type) (x: a) : erepr a (fun p -> p (Some x)) | val ereturn (a: Type) (x: a) : erepr a (fun p -> p (Some x)) | let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 61,
"start_col": 0,
"start_line": 59
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a -> LL.erepr a (fun p -> p (FStar.Pervasives.Native.Some x)) | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.option",
"LL.erepr"
] | [] | false | false | false | false | false | let ereturn (a: Type) (x: a) : erepr a (fun p -> p (Some x)) =
| fun _ -> Some x | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.find_valid_buffer_aux_ps | val find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap)
: Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) | val find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap)
: Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) | let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 381,
"start_col": 0,
"start_line": 375
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
addr: Prims.int ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h1) ==
InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h2) /\
Vale.PPC64LE.Memory.sub_list ps (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h1)))
(ensures
Vale.PPC64LE.Memory.find_valid_buffer_aux t addr ps h1 ==
Vale.PPC64LE.Memory.find_valid_buffer_aux t addr ps h2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.find_valid_buffer_aux_ps",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Vale.Interop.Types.b8",
"Prims.l_or",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Vale.PPC64LE.Memory.sub_list",
"Prims.squash",
"FStar.Pervasives.Native.option",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.find_valid_buffer_aux",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap)
: Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) =
| match ps with
| [] -> ()
| a :: q -> find_valid_buffer_aux_ps t addr q h1 h2 | false |
LL.fst | LL.ebind | val ebind
(a b: Type)
(wp_f: ewp_t a)
(wp_g: (a -> ewp_t b))
(f: erepr a wp_f)
(g: (x: a -> erepr b (wp_g x)))
: erepr b
(fun (p: epost_t b) ->
wp_f (fun (r: option a) ->
match r with
| None -> p None
| Some x -> wp_g x p)) | val ebind
(a b: Type)
(wp_f: ewp_t a)
(wp_g: (a -> ewp_t b))
(f: erepr a wp_f)
(g: (x: a -> erepr b (wp_g x)))
: erepr b
(fun (p: epost_t b) ->
wp_f (fun (r: option a) ->
match r with
| None -> p None
| Some x -> wp_g x p)) | let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x () | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 77,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
wp_f: LL.ewp_t a ->
wp_g: (_: a -> LL.ewp_t b) ->
f: LL.erepr a wp_f ->
g: (x: a -> LL.erepr b (wp_g x))
-> LL.erepr b
(fun p ->
wp_f (fun r ->
(match r with
| FStar.Pervasives.Native.None #_ -> p FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ x -> wp_g x p)
<:
Type0)) | Prims.Tot | [
"total"
] | [] | [
"LL.ewp_t",
"LL.erepr",
"Prims.unit",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"LL.epost_t",
"LL.epre_t"
] | [] | false | false | false | false | false | let ebind
(a b: Type)
(wp_f: ewp_t a)
(wp_g: (a -> ewp_t b))
(f: erepr a wp_f)
(g: (x: a -> erepr b (wp_g x)))
: erepr b
(fun (p: epost_t b) ->
wp_f (fun (r: option a) ->
match r with
| None -> p None
| Some x -> wp_g x p)) =
| fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x () | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.lemma_store_mem128 | val lemma_store_mem128 (b:buffer128) (i:nat) (v:quad32) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem128 (buffer_addr b h + scale16 i) v h == buffer_write b i v h
) | val lemma_store_mem128 (b:buffer128) (i:nat) (v:quad32) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem128 (buffer_addr b h + scale16 i) v h == buffer_write b i v h
) | let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 558,
"start_col": 0,
"start_line": 558
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.Def.Types_s.quad32 ->
h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
i < FStar.Seq.Base.length (Vale.PPC64LE.Memory.buffer_as_seq h b) /\
Vale.PPC64LE.Memory.buffer_readable h b /\ Vale.PPC64LE.Memory.buffer_writeable b)
(ensures
Vale.PPC64LE.Memory.store_mem128 (Vale.PPC64LE.Memory.buffer_addr b h +
Vale.PPC64LE.Memory.scale16 i)
v
h ==
Vale.PPC64LE.Memory.buffer_write b i v h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Prims.nat",
"Vale.Def.Types_s.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.lemma_store_mem",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_store_mem128 b i v h =
| lemma_store_mem TUInt128 b i v h | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.inv_heaplet | val inv_heaplet : owns: FStar.Set.set Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> hi: Vale.Arch.HeapImpl.vale_heap
-> Prims.logical | let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 707,
"start_col": 0,
"start_line": 698
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | owns: FStar.Set.set Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> hi: Vale.Arch.HeapImpl.vale_heap
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Set.set",
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"Prims.eq2",
"Prims.list",
"Vale.Interop.Types.b8",
"Prims.l_or",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"FStar.Ghost.reveal",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__ih",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"FStar.Set.mem",
"FStar.Map.sel",
"Prims.l_True",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_heaplet (owns: Set.set int) (h hi: vale_heap) =
| h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\
(forall (i: int).
{:pattern Set.mem i owns\/Set.mem i (Map.domain h.mh)\/Map.sel h.mh i\/Map.sel hi.mh i}
Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True) /\
True | false |
|
LL.fst | LL.get_flt | val get_flt (n: nat)
: Pure (option flt)
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n) | val get_flt (n: nat)
: Pure (option flt)
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n) | let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z }) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 175,
"start_col": 0,
"start_line": 157
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> Prims.Pure (FStar.Pervasives.Native.option LL.flt) | Prims.Pure | [] | [] | [
"Prims.nat",
"FStar.Pervasives.Native.None",
"LL.flt",
"FStar.Pervasives.Native.Some",
"LL.Mkflt",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LL.get_n1",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_True",
"Prims.eq2",
"LL.__proj__Mkflt__item__n1"
] | [] | false | false | false | false | false | let get_flt (n: nat)
: Pure (option flt)
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n) =
| let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z }) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.modifies_valid_taint | val modifies_valid_taint (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) (mt:memtaint) (tn:taint) : Lemma
(requires modifies p h h')
(ensures valid_taint_buf b h mt tn <==> valid_taint_buf b h' mt tn)
[SMTPat (modifies p h h'); SMTPat (valid_taint_buf b h' mt tn)] | val modifies_valid_taint (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) (mt:memtaint) (tn:taint) : Lemma
(requires modifies p h h')
(ensures valid_taint_buf b h mt tn <==> valid_taint_buf b h' mt tn)
[SMTPat (modifies p h h'); SMTPat (valid_taint_buf b h' mt tn)] | let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right()) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 628,
"start_col": 0,
"start_line": 612
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer t ->
p: Vale.PPC64LE.Memory.loc ->
h: Vale.Arch.HeapImpl.vale_heap ->
h': Vale.Arch.HeapImpl.vale_heap ->
mt: Vale.PPC64LE.Memory.memtaint ->
tn: Vale.Arch.HeapTypes_s.taint
-> FStar.Pervasives.Lemma (requires Vale.PPC64LE.Memory.modifies p h h')
(ensures
Vale.PPC64LE.Memory.valid_taint_buf b h mt tn <==>
Vale.PPC64LE.Memory.valid_taint_buf b h' mt tn)
[
SMTPat (Vale.PPC64LE.Memory.modifies p h h');
SMTPat (Vale.PPC64LE.Memory.valid_taint_buf b h' mt tn)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Vale.PPC64LE.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Vale.Arch.HeapTypes_s.taint",
"FStar.Classical.move_requires",
"Prims.unit",
"Vale.PPC64LE.Memory.valid_taint_buf",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.forall_intro",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Prims.op_Equality",
"Vale.PPC64LE.Memory.op_String_Access",
"Prims.int",
"Prims.op_Addition",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Vale.Arch.HeapImpl._ih",
"Prims.l_True",
"FStar.Map.sel",
"Vale.PPC64LE.Memory.apply_taint_buf",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc"
] | [] | false | false | true | false | false | let modifies_valid_taint #t b p h h' mt tn =
| let dv = get_downview b.bsrc in
let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) =
let aux (i: nat{i < DV.length dv}) : Lemma (mt.[ (_ih h').addrs b + i ] = tn) =
apply_taint_buf b h mt tn i
in
Classical.forall_intro aux
in
let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) =
let aux (i: nat{i < DV.length dv}) : Lemma (mt.[ (_ih h).addrs b + i ] = tn) =
apply_taint_buf b h' mt tn i
in
Classical.forall_intro aux
in
(Classical.move_requires imp_left ());
(Classical.move_requires imp_right ()) | false |
LL.fst | LL.bind | val bind
(a b: Type)
(wp_f: wp_t a)
(wp_g: (a -> wp_t b))
(f: repr a wp_f)
(g: (x: a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g) | val bind
(a b: Type)
(wp_f: wp_t a)
(wp_g: (a -> wp_t b))
(f: repr a wp_f)
(g: (x: a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g) | let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 261,
"start_col": 0,
"start_line": 255
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
wp_f: LL.wp_t a ->
wp_g: (_: a -> LL.wp_t b) ->
f: LL.repr a wp_f ->
g: (x: a -> LL.repr b (wp_g x))
-> LL.repr b (LL.bind_wp a b wp_f wp_g) | Prims.Tot | [
"total"
] | [] | [
"LL.wp_t",
"LL.repr",
"Prims.nat",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.Native.tuple2",
"LL.bind_wp"
] | [] | false | false | false | false | false | let bind
(a b: Type)
(wp_f: wp_t a)
(wp_g: (a -> wp_t b))
(f: repr a wp_f)
(g: (x: a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g) =
| fun n ->
let r = f n in
g (fst r) (snd r) | false |
LL.fst | LL.get_flt_exn | val get_flt_exn (n: nat)
: Exn flt
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n) | val get_flt_exn (n: nat)
: Exn flt
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n) | let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z} | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 207,
"start_col": 0,
"start_line": 197
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> LL.Exn LL.flt | LL.Exn | [] | [] | [
"Prims.nat",
"LL.Mkflt",
"LL.flt",
"FStar.Pervasives.Native.tuple2",
"LL.get_n1_exn",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Pervasives.Native.option",
"Prims.l_True",
"Prims.eq2",
"LL.__proj__Mkflt__item__n1"
] | [] | false | true | false | false | false | let get_flt_exn (n: nat)
: Exn flt
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n) =
| let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z } | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.same_memTaint | val same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint)
: Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) | val same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint)
: Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) | let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 604,
"start_col": 0,
"start_line": 600
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.PPC64LE.Memory.buffer t ->
mem0: Vale.Arch.HeapImpl.vale_heap ->
mem1: Vale.Arch.HeapImpl.vale_heap ->
memT0: Vale.PPC64LE.Memory.memtaint ->
memT1: Vale.PPC64LE.Memory.memtaint
-> FStar.Pervasives.Lemma
(requires
Vale.PPC64LE.Memory.modifies (Vale.PPC64LE.Memory.loc_buffer b) mem0 mem1 /\
(forall (p: Prims.int). FStar.Map.sel memT0 p == FStar.Map.sel memT1 p))
(ensures memT0 == memT1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.memtaint",
"Prims._assert",
"FStar.Map.equal",
"Prims.int",
"Vale.Arch.HeapTypes_s.taint",
"Prims.unit",
"Prims.l_and",
"Vale.PPC64LE.Memory.modifies",
"Vale.PPC64LE.Memory.loc_buffer",
"Prims.l_Forall",
"Prims.eq2",
"FStar.Map.sel",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint)
: Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
| assert (Map.equal memT0 memT1) | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.fadd_mul_r | val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul))) | val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul)
(LSeq.map2 (Vec.pfadd) (feval h0 acc) (feval h0 f1)) (feval h0 (gsub p 0ul 5ul))) | let fadd_mul_r #w out f1 p =
let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let (o0, o1, o2, o3, o4) =
fadd_mul_r5 #w (a0, a1, a2, a3, a4) (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4 | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 345,
"start_col": 0,
"start_line": 311
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f)))
let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i)
#pop-options
inline_for_extraction noextract
val set_bit128:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 128))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == LSeq.map (Vec.pfadd (pow2 128)) (feval h0 f))
let set_bit128 #w f =
let b = u64 0x1000000 in
assert_norm (0x1000000 = pow2 24);
assert (v b == v (u64 1 <<. 24ul));
let mask = vec_load b w in
let f4 = f.(4ul) in
let h0 = ST.get () in
f.(4ul) <- vec_or f4 mask;
set_bit5_lemma (as_seq h0 f) 128
inline_for_extraction noextract
val set_zero:
#w:lanes
-> f:felem w
-> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (0, 0, 0, 0, 0) /\
feval h1 f == LSeq.create w 0)
let set_zero #w f =
f.(0ul) <- zero w;
f.(1ul) <- zero w;
f.(2ul) <- zero w;
f.(3ul) <- zero w;
f.(4ul) <- zero w;
let h1 = ST.get () in
LSeq.eq_intro (feval h1 f) (LSeq.create w 0)
inline_for_extraction noextract
val copy_felem:
#w:lanes
-> #m:scale32_5
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ disjoint f1 f2 /\
felem_fits h f2 m)
(ensures fun h0 _ h1 ->
modifies (loc f1) h0 h1 /\
felem_fits h1 f1 m /\
as_tup5 h1 f1 == as_tup5 h0 f2)
let copy_felem #w #m f1 f2 =
f1.(0ul) <- f2.(0ul);
f1.(1ul) <- f2.(1ul);
f1.(2ul) <- f2.(2ul);
f1.(3ul) <- f2.(3ul);
f1.(4ul) <- f2.(4ul)
inline_for_extraction noextract
val fadd:
#w:lanes
-> out:felem w
-> f1:felem w
-> f2:felem w
-> Stack unit
(requires fun h ->
live h f1 /\ live h f2 /\ live h out /\
felem_fits h f1 (2,2,2,2,2) /\
felem_fits h f2 (1,1,1,1,1))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
//as_tup5 h1 out == fadd5 (as_tup5 h0 f1) (as_tup5 h0 f2) /\
felem_fits h1 out (3,3,3,3,3) /\
feval h1 out == LSeq.map2 Vec.pfadd (feval h0 f1) (feval h0 f2))
let fadd #w out f1 f2 =
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let f20 = f2.(0ul) in
let f21 = f2.(1ul) in
let f22 = f2.(2ul) in
let f23 = f2.(3ul) in
let f24 = f2.(4ul) in
let (o0,o1,o2,o3,o4) =
fadd5 #w (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#push-options "--max_fuel 1"
inline_for_extraction noextract
val fmul_r:
#w:lanes
-> out:felem w
-> f1:felem w
-> r:felem w
-> r5:felem w
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\
live h r /\ live h r5 /\
felem_fits h f1 (3,3,3,3,3) /\
felem_fits h r (2,2,2,2,2) /\
felem_fits h r5 (10,10,10,10,10) /\
as_tup5 h r5 == precomp_r5 (as_tup5 h r))
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (1,2,1,1,2) /\
feval h1 out == LSeq.map2 (Vec.pfmul) (feval h0 f1) (feval h0 r))
let fmul_r #w out f1 r r5 =
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r5 #w (f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4) (r50, r51, r52, r53, r54) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
#pop-options
inline_for_extraction noextract
val fadd_mul_r:
#w:lanes
-> acc:felem w
-> f1:felem w
-> p:precomp_r w
-> Stack unit
(requires fun h ->
live h acc /\ live h f1 /\ live h p /\
felem_fits h acc (2,2,2,2,2) /\
felem_fits h f1 (1,1,1,1,1) /\
fmul_precomp_r_pre h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (1,2,1,1,2) /\
feval h1 acc == LSeq.map2 (Vec.pfmul) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
acc: Hacl.Impl.Poly1305.Field32xN.felem w ->
f1: Hacl.Impl.Poly1305.Field32xN.felem w ->
p: Hacl.Impl.Poly1305.Field32xN.precomp_r w
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.felem",
"Hacl.Impl.Poly1305.Field32xN.precomp_r",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.Buffer.op_Array_Assignment",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.fadd_mul_r5",
"FStar.Pervasives.Native.Mktuple5",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let fadd_mul_r #w out f1 p =
| let r = sub p 0ul 5ul in
let r5 = sub p 5ul 5ul in
let r0 = r.(0ul) in
let r1 = r.(1ul) in
let r2 = r.(2ul) in
let r3 = r.(3ul) in
let r4 = r.(4ul) in
let r50 = r5.(0ul) in
let r51 = r5.(1ul) in
let r52 = r5.(2ul) in
let r53 = r5.(3ul) in
let r54 = r5.(4ul) in
let f10 = f1.(0ul) in
let f11 = f1.(1ul) in
let f12 = f1.(2ul) in
let f13 = f1.(3ul) in
let f14 = f1.(4ul) in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let o0, o1, o2, o3, o4 =
fadd_mul_r5 #w
(a0, a1, a2, a3, a4)
(f10, f11, f12, f13, f14)
(r0, r1, r2, r3, r4)
(r50, r51, r52, r53, r54)
in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4 | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_layout_data_buffer | val valid_layout_data_buffer : t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.PPC64LE.Memory.buffer t ->
layout: Vale.Arch.HeapImpl.vale_heap_layout_inner ->
hid: Vale.Arch.HeapImpl.heaplet_id ->
write: Prims.bool
-> Prims.logical | let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 685,
"start_col": 0,
"start_line": 679
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.PPC64LE.Memory.buffer t ->
layout: Vale.Arch.HeapImpl.vale_heap_layout_inner ->
hid: Vale.Arch.HeapImpl.heaplet_id ->
write: Prims.bool
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.bool",
"Prims.l_Exists",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers",
"Prims.eq2",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Interop.Types.b8",
"Prims.l_or",
"Prims.int",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Interop.Types.view_n",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"Prims.l_imp",
"Vale.Arch.HeapImpl.mutability",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_mutable",
"Vale.Arch.HeapImpl.Mutable",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"FStar.Seq.Base.index",
"Prims.logical"
] | [] | false | false | false | false | true | let valid_layout_data_buffer
(t: base_typ)
(b: buffer t)
(layout: vale_heap_layout_inner)
(hid: heaplet_id)
(write: bool)
=
| exists (n: nat). {:pattern (Seq.index layout.vl_buffers n)}
n < Seq.length layout.vl_buffers /\
(let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet) | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.lemma_store_mem64 | val lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem64 (buffer_addr b h + scale8 i) v h == buffer_write b i v h
) | val lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem64 (buffer_addr b h + scale8 i) v h == buffer_write b i v h
) | let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 540,
"start_col": 0,
"start_line": 540
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.PPC64LE.Memory.buffer64 ->
i: Prims.nat ->
v: Vale.Def.Types_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
i < FStar.Seq.Base.length (Vale.PPC64LE.Memory.buffer_as_seq h b) /\
Vale.PPC64LE.Memory.buffer_readable h b /\ Vale.PPC64LE.Memory.buffer_writeable b)
(ensures
Vale.PPC64LE.Memory.store_mem64 (Vale.PPC64LE.Memory.buffer_addr b h +
Vale.PPC64LE.Memory.scale8 i)
v
h ==
Vale.PPC64LE.Memory.buffer_write b i v h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.PPC64LE.Memory.buffer64",
"Prims.nat",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.PPC64LE.Memory.lemma_store_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_store_mem64 b i v h =
| lemma_store_mem TUInt64 b i v h | false |
Hacl.Impl.Poly1305.Field32xN.fst | Hacl.Impl.Poly1305.Field32xN.set_bit | val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) | val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i);
feval h1 f == LSeq.map (Vec.pfadd (pow2 (v i))) (feval h0 f))) | let set_bit #w f i =
let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i) | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 142,
"start_col": 0,
"start_line": 136
} | module Hacl.Impl.Poly1305.Field32xN
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.IntVector
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
open Hacl.Impl.Poly1305.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
inline_for_extraction noextract
let felem (w:lanes) = lbuffer (uint64xN w) 5ul
inline_for_extraction noextract
let felem_wide (w:lanes) = felem w
inline_for_extraction noextract
let precomp_r (w:lanes) = lbuffer (uint64xN w) 20ul
unfold noextract
let op_String_Access #a #len = LSeq.index #a #len
noextract
val as_tup5: #w:lanes -> h:mem -> f:felem w -> GTot (felem5 w)
let as_tup5 #w h f =
let s = as_seq h f in
let s0 = s.[0] in
let s1 = s.[1] in
let s2 = s.[2] in
let s3 = s.[3] in
let s4 = s.[4] in
(s0,s1,s2,s3,s4)
noextract
val felem_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_fits #w h f m =
felem_fits5 (as_tup5 h f) m
noextract
val felem_wide_fits: #w:lanes -> h:mem -> f:felem w -> m:scale32_5 -> Type0
let felem_wide_fits #w h f m =
felem_wide_fits5 (as_tup5 h f) m
noextract
let feval (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq Vec.pfelem w) =
feval5 (as_tup5 h f)
noextract
let fas_nat (#w:lanes) (h:mem) (f:felem w) : GTot (LSeq.lseq nat w) =
fas_nat5 (as_tup5 h f)
noextract
let felem_less (#w:lanes) (h:mem) (f:felem w) (max:nat) : Type0 =
felem_less5 (as_tup5 h f) max
val lemma_feval_is_fas_nat:
#w:lanes
-> h:mem
-> f:felem w
-> Lemma
(requires felem_less h f (pow2 128))
(ensures (forall (i:nat). i < w ==> (feval h f).[i] == (fas_nat h f).[i]))
let lemma_feval_is_fas_nat #w h f =
lemma_feval_is_fas_nat (as_tup5 h f)
inline_for_extraction noextract
val fmul_precomp_r_pre:
#w:lanes
-> h:mem
-> precomp:precomp_r w
-> Type0
let fmul_precomp_r_pre #w h precomp =
let r = gsub precomp 0ul 5ul in
let r_5 = gsub precomp 5ul 5ul in
felem_fits h r (1, 1, 1, 1, 1) /\
felem_fits h r_5 (5, 5, 5, 5, 5) /\
as_tup5 h r_5 == precomp_r5 (as_tup5 h r)
noextract
val load_precompute_r_post:
#w:lanes
-> h:mem
-> p:precomp_r w
-> Type0
let load_precompute_r_post #w h p =
assert_norm (pow2 128 < Vec.prime);
let r = gsub p 0ul 5ul in
let rn = gsub p 10ul 5ul in
let rn_5 = gsub p 15ul 5ul in
fmul_precomp_r_pre h p /\
felem_fits h rn (2, 2, 2, 2, 2) /\
felem_fits h rn_5 (10, 10, 10, 10, 10) /\
as_tup5 h rn_5 == precomp_r5 (as_tup5 h rn) /\
feval h rn == Vec.compute_rw (feval h r).[0]
inline_for_extraction noextract
val create_felem:
w:lanes
-> StackInline (felem w)
(requires fun h -> True)
(ensures fun h0 b h1 ->
stack_allocated b h0 h1 (LSeq.create 5 (zero w)) /\
feval h1 b == LSeq.create w 0)
let create_felem w =
let r = create 5ul (zero w) in
let h1 = ST.get () in
LSeq.eq_intro (feval h1 r) (LSeq.create w 0);
r
#push-options "--z3rlimit 100"
inline_for_extraction noextract
val set_bit:
#w:lanes
-> f:felem w
-> i:size_t{size_v i <= 128}
-> Stack unit
(requires fun h ->
live h f /\
felem_fits h f (1, 1, 1, 1, 1) /\
felem_less #w h f (pow2 (v i)))
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(Math.Lemmas.pow2_le_compat 128 (v i); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.Impl.Poly1305.Field32xN.felem w -> i: Lib.IntTypes.size_t{Lib.IntTypes.size_v i <= 128}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Impl.Poly1305.Field32xN.felem",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.size_v",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.set_bit5_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.unit",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntVector.vec_or",
"Lib.IntTypes.U64",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.op_Array_Access",
"Lib.IntVector.vec_t",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Lib.Sequence.create",
"Lib.IntVector.vec_load",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.u64",
"Lib.IntTypes.op_Percent_Dot"
] | [] | false | true | false | false | false | let set_bit #w f i =
| let b = u64 1 <<. (i %. 26ul) in
let mask = vec_load b w in
let fi = f.(i /. 26ul) in
let h0 = ST.get () in
f.(i /. 26ul) <- vec_or fi mask;
set_bit5_lemma (as_seq h0 f) (v i) | false |
LL.fst | LL.return | val return (a: Type) (x: a) : repr a (fun p n -> p (Some (x, n))) | val return (a: Type) (x: a) : repr a (fun p n -> p (Some (x, n))) | let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 236,
"start_col": 0,
"start_line": 234
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a -> LL.repr a (fun p n -> p (FStar.Pervasives.Native.Some (x, n))) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"LL.repr",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some"
] | [] | false | false | false | false | false | let return (a: Type) (x: a) : repr a (fun p n -> p (Some (x, n))) =
| fun n -> (x, n) | false |
LL.fst | LL.get_flt_stexn_reified | val get_flt_stexn_reified (n: nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n) | val get_flt_stexn_reified (n: nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n) | let get_flt_stexn_reified (n:nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= reify (reify (get_flt_stexn ()) n) () | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 345,
"start_col": 0,
"start_line": 338
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n)))
inline_for_extraction
let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n)
sub_effect PURE ~> STEXN = lift_pure_stexn
effect StExn (a:Type) (pre:nat -> Type0) (post:nat -> option (a & nat) -> Type0) =
STEXN a (fun p n -> pre n /\ (forall r. post n r ==> p r))
(*** Example using the STEXN effect ***)
inline_for_extraction
let get_n1_stexn (_:unit)
: StExn nat
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= STEXN?.reflect (fun n -> get_n1_exn n)
/// get_flt function in the STEXN effect that hides the state also
inline_for_extraction
let get_flt_stexn (_:unit)
: StExn flt
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= let x = get_n1_stexn () in
let y = get_n1_stexn () in
let z = get_n1_stexn () in
{ n1 = x; n2 = y; n3 = z}
/// And now we can reify the effect to reveal a spec in terms of PURE | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> Prims.Pure (FStar.Pervasives.Native.option (LL.flt * Prims.nat)) | Prims.Pure | [] | [] | [
"Prims.nat",
"LL.get_flt_stexn",
"LL.flt",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.option",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_True",
"Prims.eq2",
"LL.__proj__Mkflt__item__n1"
] | [] | false | false | false | false | false | let get_flt_stexn_reified (n: nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n) =
| reify (reify (get_flt_stexn ()) n) () | false |
LL.fst | LL.subcomp | val subcomp (a: Type) (wp_f wp_g: wp_t a) (f: repr a wp_f)
: Pure (repr a wp_g) (requires forall p n. wp_g p n ==> wp_f p n) (ensures fun _ -> True) | val subcomp (a: Type) (wp_f wp_g: wp_t a) (f: repr a wp_f)
: Pure (repr a wp_g) (requires forall p n. wp_g p n ==> wp_f p n) (ensures fun _ -> True) | let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 270,
"start_col": 0,
"start_line": 264
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> wp_f: LL.wp_t a -> wp_g: LL.wp_t a -> f: LL.repr a wp_f -> Prims.Pure (LL.repr a wp_g) | Prims.Pure | [] | [] | [
"LL.wp_t",
"LL.repr",
"Prims.l_Forall",
"LL.post_t",
"Prims.nat",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let subcomp (a: Type) (wp_f wp_g: wp_t a) (f: repr a wp_f)
: Pure (repr a wp_g) (requires forall p n. wp_g p n ==> wp_f p n) (ensures fun _ -> True) =
| f | false |
LL.fst | LL.lift_pure_stexn | val lift_pure_stexn (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp))
: repr a (lift_pure_wp_stexn wp) | val lift_pure_stexn (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp))
: repr a (lift_pure_wp_stexn wp) | let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 298,
"start_col": 0,
"start_line": 295
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> wp: Prims.pure_wp a -> f: (_: Prims.unit -> Prims.PURE a)
-> LL.repr a (LL.lift_pure_wp_stexn wp) | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"Prims.unit",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"LL.repr",
"LL.lift_pure_wp_stexn"
] | [] | false | false | false | false | false | let lift_pure_stexn (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp))
: repr a (lift_pure_wp_stexn wp) =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.inv_heaplets | val inv_heaplets : layout: Vale.Arch.HeapImpl.vale_heap_layout_inner ->
h: Vale.Arch.HeapImpl.vale_heap ->
hs: Vale.Arch.HeapImpl.vale_heaplets ->
mt: Vale.Arch.HeapTypes_s.memTaint_t
-> Prims.logical | let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 736,
"start_col": 0,
"start_line": 724
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
layout: Vale.Arch.HeapImpl.vale_heap_layout_inner ->
h: Vale.Arch.HeapImpl.vale_heap ->
hs: Vale.Arch.HeapImpl.vale_heaplets ->
mt: Vale.Arch.HeapTypes_s.memTaint_t
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.HeapImpl.vale_heaplets",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Prims.l_and",
"Vale.PPC64LE.Memory.modifies",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_mod_loc",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap",
"Prims.l_Forall",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.int",
"Prims.l_iff",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplet_map",
"FStar.Pervasives.Native.Some",
"Prims.b2t",
"FStar.Set.mem",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplet_sets",
"Vale.PPC64LE.Memory.inv_heaplet",
"Vale.Lib.Map16.sel",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.PPC64LE.Memory.inv_buffer_info",
"FStar.Seq.Base.index",
"Vale.PPC64LE.Memory.buffer_info_disjoint",
"Prims.l_True",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_heaplets
(layout: vale_heap_layout_inner)
(h: vale_heap)
(hs: vale_heaplets)
(mt: memTaint_t)
=
| let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)) /\
(forall (i: heaplet_id). {:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i: nat). {:pattern (Seq.index bs i)}
i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1: nat) (i2: nat). {:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==>
buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True | false |
|
LL.fst | LL.bind_wp | val bind_wp (a b: Type) (wp_f: wp_t a) (wp_g: (a -> wp_t b)) : wp_t b | val bind_wp (a b: Type) (wp_f: wp_t a) (wp_g: (a -> wp_t b)) : wp_t b | let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0 | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 251,
"start_col": 0,
"start_line": 246
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> wp_f: LL.wp_t a -> wp_g: (_: a -> LL.wp_t b) -> LL.wp_t b | Prims.Tot | [
"total"
] | [] | [
"LL.wp_t",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | true | false | let bind_wp (a b: Type) (wp_f: wp_t a) (wp_g: (a -> wp_t b)) : wp_t b =
| fun p n0 ->
wp_f (function
| None -> p None
| Some (x, n1) -> (wp_g x) p n1)
n0 | false |
LL.fst | LL.post_a | val post_a (a b: Type) (wp_g: (a -> wp_t b)) (p: post_t b) : post_t a | val post_a (a b: Type) (wp_g: (a -> wp_t b)) (p: post_t b) : post_t a | let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 243,
"start_col": 0,
"start_line": 239
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> wp_g: (_: a -> LL.wp_t b) -> p: LL.post_t b -> LL.post_t a | Prims.Tot | [
"total"
] | [] | [
"LL.wp_t",
"LL.post_t",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | true | false | let post_a (a b: Type) (wp_g: (a -> wp_t b)) (p: post_t b) : post_t a =
| function
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_layout_buffer_id | val valid_layout_buffer_id (t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h_id:option heaplet_id) (write:bool) : prop0 | val valid_layout_buffer_id (t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h_id:option heaplet_id) (write:bool) : prop0 | let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 693,
"start_col": 0,
"start_line": 688
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.PPC64LE.Memory.buffer t ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
h_id: FStar.Pervasives.Native.option Vale.Arch.HeapImpl.heaplet_id ->
write: Prims.bool
-> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.PPC64LE.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.bool",
"Prims.l_True",
"Prims.l_and",
"Prims.b2t",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.PPC64LE.Memory.valid_layout_data_buffer",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | false | false | let valid_layout_buffer_id t b layout h_id write =
| match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write | false |
LL.fst | LL.lift_pure_wp_stexn | val lift_pure_wp_stexn (#a: Type) (wp: pure_wp a) : wp_t a | val lift_pure_wp_stexn (#a: Type) (wp: pure_wp a) : wp_t a | let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n))) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 292,
"start_col": 0,
"start_line": 290
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | wp: Prims.pure_wp a -> LL.wp_t a | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.l_True",
"Prims.nat",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.pure_pre",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"LL.wp_t"
] | [] | false | false | false | true | false | let lift_pure_wp_stexn (#a: Type) (wp: pure_wp a) : wp_t a =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n))) | false |
LL.fst | LL.get_n1_exn | val get_n1_exn (n: nat)
: Exn (nat * nat)
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1) | val get_n1_exn (n: nat)
: Exn (nat * nat)
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1) | let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 190,
"start_col": 0,
"start_line": 183
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> LL.Exn (Prims.nat * Prims.nat) | LL.Exn | [] | [] | [
"Prims.nat",
"Prims.unit",
"LL.get_n1",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition"
] | [] | false | true | false | false | false | let get_n1_exn (n: nat)
: Exn (nat * nat)
(requires n > 0)
(ensures
fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1) =
| EXN?.reflect (fun _ -> get_n1 n) | false |
Hacl.Impl.Poly1305.fst | Hacl.Impl.Poly1305.poly1305_mac | val poly1305_mac: #s:field_spec ->
poly1305_mac_st s | val poly1305_mac: #s:field_spec ->
poly1305_mac_st s | let poly1305_mac #s output input input_len key =
push_frame ();
let ctx = create (nlimb s +! precomplen s) (limb_zero s) in
poly1305_init #s ctx key;
poly1305_update #s ctx input_len input;
poly1305_finish #s output key ctx;
pop_frame () | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 615,
"start_col": 0,
"start_line": 609
} | module Hacl.Impl.Poly1305
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Fields
open Hacl.Impl.Poly1305.Bignum128
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
module LSeq = Lib.Sequence
module S = Spec.Poly1305
module Vec = Hacl.Spec.Poly1305.Vec
module Equiv = Hacl.Spec.Poly1305.Equiv
module F32xN = Hacl.Impl.Poly1305.Field32xN
friend Lib.LoopCombinators
let _: squash (inversion field_spec) = allow_inversion field_spec
#reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq' --record_options"
inline_for_extraction noextract
let get_acc #s (ctx:poly1305_ctx s) : Stack (felem s)
(requires fun h -> live h ctx)
(ensures fun h0 acc h1 -> h0 == h1 /\ live h1 acc /\ acc == gsub ctx 0ul (nlimb s))
= sub ctx 0ul (nlimb s)
inline_for_extraction noextract
let get_precomp_r #s (ctx:poly1305_ctx s) : Stack (precomp_r s)
(requires fun h -> live h ctx)
(ensures fun h0 pre h1 -> h0 == h1 /\ live h1 pre /\ pre == gsub ctx (nlimb s) (precomplen s))
= sub ctx (nlimb s) (precomplen s)
unfold
let op_String_Access #a #len = LSeq.index #a #len
let as_get_acc #s h ctx = (feval h (gsub ctx 0ul (nlimb s))).[0]
let as_get_r #s h ctx = (feval h (gsub ctx (nlimb s) (nlimb s))).[0]
let state_inv_t #s h ctx =
felem_fits h (gsub ctx 0ul (nlimb s)) (2, 2, 2, 2, 2) /\
F32xN.load_precompute_r_post #(width s) h (gsub ctx (nlimb s) (precomplen s))
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --record_options"
let reveal_ctx_inv' #s ctx ctx' h0 h1 =
let acc_b = gsub ctx 0ul (nlimb s) in
let acc_b' = gsub ctx' 0ul (nlimb s) in
let r_b = gsub ctx (nlimb s) (nlimb s) in
let r_b' = gsub ctx' (nlimb s) (nlimb s) in
let precom_b = gsub ctx (nlimb s) (precomplen s) in
let precom_b' = gsub ctx' (nlimb s) (precomplen s) in
as_seq_gsub h0 ctx 0ul (nlimb s);
as_seq_gsub h1 ctx 0ul (nlimb s);
as_seq_gsub h0 ctx (nlimb s) (nlimb s);
as_seq_gsub h1 ctx (nlimb s) (nlimb s);
as_seq_gsub h0 ctx (nlimb s) (precomplen s);
as_seq_gsub h1 ctx (nlimb s) (precomplen s);
as_seq_gsub h0 ctx' 0ul (nlimb s);
as_seq_gsub h1 ctx' 0ul (nlimb s);
as_seq_gsub h0 ctx' (nlimb s) (nlimb s);
as_seq_gsub h1 ctx' (nlimb s) (nlimb s);
as_seq_gsub h0 ctx' (nlimb s) (precomplen s);
as_seq_gsub h1 ctx' (nlimb s) (precomplen s);
assert (as_seq h0 acc_b == as_seq h1 acc_b');
assert (as_seq h0 r_b == as_seq h1 r_b');
assert (as_seq h0 precom_b == as_seq h1 precom_b')
val fmul_precomp_inv_zeros: #s:field_spec -> precomp_b:lbuffer (limb s) (precomplen s) -> h:mem ->
Lemma
(requires as_seq h precomp_b == Lib.Sequence.create (v (precomplen s)) (limb_zero s))
(ensures F32xN.fmul_precomp_r_pre #(width s) h precomp_b)
let fmul_precomp_inv_zeros #s precomp_b h =
let r_b = gsub precomp_b 0ul (nlimb s) in
let r_b5 = gsub precomp_b (nlimb s) (nlimb s) in
as_seq_gsub h precomp_b 0ul (nlimb s);
as_seq_gsub h precomp_b (nlimb s) (nlimb s);
Hacl.Spec.Poly1305.Field32xN.Lemmas.precomp_r5_zeros (width s);
LSeq.eq_intro (feval h r_b) (LSeq.create (width s) 0);
LSeq.eq_intro (feval h r_b5) (LSeq.create (width s) 0);
assert (F32xN.as_tup5 #(width s) h r_b5 == F32xN.precomp_r5 (F32xN.as_tup5 h r_b))
val precomp_inv_zeros: #s:field_spec -> precomp_b:lbuffer (limb s) (precomplen s) -> h:mem ->
Lemma
(requires as_seq h precomp_b == Lib.Sequence.create (v (precomplen s)) (limb_zero s))
(ensures F32xN.load_precompute_r_post #(width s) h precomp_b)
#push-options "--z3rlimit 150"
let precomp_inv_zeros #s precomp_b h =
let r_b = gsub precomp_b 0ul (nlimb s) in
let rn_b = gsub precomp_b (2ul *! nlimb s) (nlimb s) in
let rn_b5 = gsub precomp_b (3ul *! nlimb s) (nlimb s) in
as_seq_gsub h precomp_b 0ul (nlimb s);
as_seq_gsub h precomp_b (2ul *! nlimb s) (nlimb s);
as_seq_gsub h precomp_b (3ul *! nlimb s) (nlimb s);
fmul_precomp_inv_zeros #s precomp_b h;
Hacl.Spec.Poly1305.Field32xN.Lemmas.precomp_r5_zeros (width s);
LSeq.eq_intro (feval h r_b) (LSeq.create (width s) 0);
LSeq.eq_intro (feval h rn_b) (LSeq.create (width s) 0);
LSeq.eq_intro (feval h rn_b5) (LSeq.create (width s) 0);
assert (F32xN.as_tup5 #(width s) h rn_b5 == F32xN.precomp_r5 (F32xN.as_tup5 h rn_b));
assert (feval h rn_b == Vec.compute_rw (feval h r_b).[0])
#pop-options
let ctx_inv_zeros #s ctx h =
// ctx = [acc_b; r_b; r_b5; rn_b; rn_b5]
let acc_b = gsub ctx 0ul (nlimb s) in
as_seq_gsub h ctx 0ul (nlimb s);
LSeq.eq_intro (feval h acc_b) (LSeq.create (width s) 0);
assert (felem_fits h acc_b (2, 2, 2, 2, 2));
let precomp_b = gsub ctx (nlimb s) (precomplen s) in
LSeq.eq_intro (as_seq h precomp_b) (Lib.Sequence.create (v (precomplen s)) (limb_zero s));
precomp_inv_zeros #s precomp_b h
#reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq' --record_options"
inline_for_extraction noextract
val poly1305_encode_block:
#s:field_spec
-> f:felem s
-> b:lbuffer uint8 16ul ->
Stack unit
(requires fun h ->
live h b /\ live h f /\ disjoint b f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(feval h1 f).[0] == S.encode 16 (as_seq h0 b))
let poly1305_encode_block #s f b =
load_felem_le f b;
set_bit128 f
inline_for_extraction noextract
val poly1305_encode_blocks:
#s:field_spec
-> f:felem s
-> b:lbuffer uint8 (blocklen s) ->
Stack unit
(requires fun h ->
live h b /\ live h f /\ disjoint b f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
feval h1 f == Vec.load_blocks #(width s) (as_seq h0 b))
let poly1305_encode_blocks #s f b =
load_felems_le f b;
set_bit128 f
inline_for_extraction noextract
val poly1305_encode_last:
#s:field_spec
-> f:felem s
-> len:size_t{v len < 16}
-> b:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h f /\ disjoint b f)
(ensures fun h0 _ h1 ->
modifies (loc f) h0 h1 /\
felem_fits h1 f (1, 1, 1, 1, 1) /\
(feval h1 f).[0] == S.encode (v len) (as_seq h0 b))
let poly1305_encode_last #s f len b =
push_frame();
let tmp = create 16ul (u8 0) in
update_sub tmp 0ul len b;
let h0 = ST.get () in
Hacl.Impl.Poly1305.Lemmas.nat_from_bytes_le_eq_lemma (v len) (as_seq h0 b);
assert (BSeq.nat_from_bytes_le (as_seq h0 b) == BSeq.nat_from_bytes_le (as_seq h0 tmp));
assert (BSeq.nat_from_bytes_le (as_seq h0 b) < pow2 (v len * 8));
load_felem_le f tmp;
let h1 = ST.get () in
lemma_feval_is_fas_nat h1 f;
set_bit f (len *! 8ul);
pop_frame()
inline_for_extraction noextract
val poly1305_encode_r:
#s:field_spec
-> p:precomp_r s
-> b:lbuffer uint8 16ul ->
Stack unit
(requires fun h ->
live h b /\ live h p /\ disjoint b p)
(ensures fun h0 _ h1 ->
modifies (loc p) h0 h1 /\
F32xN.load_precompute_r_post #(width s) h1 p /\
(feval h1 (gsub p 0ul 5ul)).[0] == S.poly1305_encode_r (as_seq h0 b))
let poly1305_encode_r #s p b =
let lo = uint_from_bytes_le (sub b 0ul 8ul) in
let hi = uint_from_bytes_le (sub b 8ul 8ul) in
let mask0 = u64 0x0ffffffc0fffffff in
let mask1 = u64 0x0ffffffc0ffffffc in
let lo = lo &. mask0 in
let hi = hi &. mask1 in
load_precompute_r p lo hi
[@ Meta.Attribute.specialize ]
let poly1305_init #s ctx key =
let acc = get_acc ctx in
let pre = get_precomp_r ctx in
let kr = sub key 0ul 16ul in
set_zero acc;
poly1305_encode_r #s pre kr
inline_for_extraction noextract
val update1:
#s:field_spec
-> p:precomp_r s
-> b:lbuffer uint8 16ul
-> acc:felem s ->
Stack unit
(requires fun h ->
live h p /\ live h b /\ live h acc /\
disjoint p acc /\ disjoint b acc /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.fmul_precomp_r_pre #(width s) h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (2, 2, 2, 2, 2) /\
(feval h1 acc).[0] == S.poly1305_update1
(feval h0 (gsub p 0ul 5ul)).[0] 16 (as_seq h0 b) (feval h0 acc).[0])
let update1 #s pre b acc =
push_frame ();
let e = create (nlimb s) (limb_zero s) in
poly1305_encode_block e b;
fadd_mul_r acc e pre;
pop_frame ()
let poly1305_update1 #s ctx text =
let pre = get_precomp_r ctx in
let acc = get_acc ctx in
update1 pre text acc
inline_for_extraction noextract
val poly1305_update_last:
#s:field_spec
-> p:precomp_r s
-> len:size_t{v len < 16}
-> b:lbuffer uint8 len
-> acc:felem s ->
Stack unit
(requires fun h ->
live h p /\ live h b /\ live h acc /\
disjoint p acc /\ disjoint b acc /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.fmul_precomp_r_pre #(width s) h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (2, 2, 2, 2, 2) /\
(feval h1 acc).[0] == S.poly1305_update1
(feval h0 (gsub p 0ul 5ul)).[0] (v len) (as_seq h0 b) (feval h0 acc).[0])
#push-options "--z3rlimit 200"
let poly1305_update_last #s pre len b acc =
push_frame ();
let e = create (nlimb s) (limb_zero s) in
poly1305_encode_last e len b;
fadd_mul_r acc e pre;
pop_frame ()
#pop-options
inline_for_extraction noextract
val poly1305_update_nblocks:
#s:field_spec
-> p:precomp_r s
-> b:lbuffer uint8 (blocklen s)
-> acc:felem s ->
Stack unit
(requires fun h ->
live h p /\ live h b /\ live h acc /\
disjoint acc p /\ disjoint acc b /\
felem_fits h acc (3, 3, 3, 3, 3) /\
F32xN.load_precompute_r_post #(width s) h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
feval h1 acc ==
Vec.poly1305_update_nblocks #(width s) (feval h0 (gsub p 10ul 5ul)) (as_seq h0 b) (feval h0 acc))
let poly1305_update_nblocks #s pre b acc =
push_frame ();
let e = create (nlimb s) (limb_zero s) in
poly1305_encode_blocks e b;
fmul_rn acc acc pre;
fadd acc acc e;
pop_frame ()
inline_for_extraction noextract
val poly1305_update1_f:
#s:field_spec
-> p:precomp_r s
-> nb:size_t
-> len:size_t{v nb == v len / 16}
-> text:lbuffer uint8 len
-> i:size_t{v i < v nb}
-> acc:felem s ->
Stack unit
(requires fun h ->
live h p /\ live h text /\ live h acc /\
disjoint acc p /\ disjoint acc text /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.fmul_precomp_r_pre #(width s) h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (2, 2, 2, 2, 2) /\
(feval h1 acc).[0] ==
LSeq.repeat_blocks_f #uint8 #S.felem 16
(as_seq h0 text) (S.poly1305_update1 (feval h0 (gsub p 0ul 5ul)).[0] 16) (v nb) (v i) (feval h0 acc).[0])
let poly1305_update1_f #s pre nb len text i acc=
assert ((v i + 1) * 16 <= v nb * 16);
let block = sub #_ #_ #len text (i *! 16ul) 16ul in
update1 #s pre block acc
#push-options "--z3rlimit 100 --max_fuel 1"
inline_for_extraction noextract
val poly1305_update_scalar:
#s:field_spec
-> len:size_t
-> text:lbuffer uint8 len
-> pre:precomp_r s
-> acc:felem s ->
Stack unit
(requires fun h ->
live h text /\ live h acc /\ live h pre /\
disjoint acc text /\ disjoint acc pre /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.fmul_precomp_r_pre #(width s) h pre)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (2, 2, 2, 2, 2) /\
(feval h1 acc).[0] ==
S.poly1305_update (as_seq h0 text) (feval h0 acc).[0] (feval h0 (gsub pre 0ul 5ul)).[0])
let poly1305_update_scalar #s len text pre acc =
let nb = len /. 16ul in
let rem = len %. 16ul in
let h0 = ST.get () in
LSeq.lemma_repeat_blocks #uint8 #S.felem 16 (as_seq h0 text)
(S.poly1305_update1 (feval h0 (gsub pre 0ul 5ul)).[0] 16)
(S.poly1305_update_last (feval h0 (gsub pre 0ul 5ul)).[0])
(feval h0 acc).[0];
[@ inline_let]
let spec_fh h0 =
LSeq.repeat_blocks_f 16 (as_seq h0 text)
(S.poly1305_update1 (feval h0 (gsub pre 0ul 5ul)).[0] 16) (v nb) in
[@ inline_let]
let inv h (i:nat{i <= v nb}) =
modifies1 acc h0 h /\
live h pre /\ live h text /\ live h acc /\
disjoint acc pre /\ disjoint acc text /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.fmul_precomp_r_pre #(width s) h pre /\
(feval h acc).[0] == Lib.LoopCombinators.repeati i (spec_fh h0) (feval h0 acc).[0] in
Lib.Loops.for (size 0) nb inv
(fun i ->
Lib.LoopCombinators.unfold_repeati (v nb) (spec_fh h0) (feval h0 acc).[0] (v i);
poly1305_update1_f #s pre nb len text i acc);
let h1 = ST.get () in
assert ((feval h1 acc).[0] == Lib.LoopCombinators.repeati (v nb) (spec_fh h0) (feval h0 acc).[0]);
if rem >. 0ul then (
let last = sub text (nb *! 16ul) rem in
as_seq_gsub h1 text (nb *! 16ul) rem;
assert (disjoint acc last);
poly1305_update_last #s pre rem last acc)
#pop-options
inline_for_extraction noextract
val poly1305_update_multi_f:
#s:field_spec
-> p:precomp_r s
-> bs:size_t{v bs == width s * S.size_block}
-> nb:size_t
-> len:size_t{v nb == v len / v bs /\ v len % v bs == 0}
-> text:lbuffer uint8 len
-> i:size_t{v i < v nb}
-> acc:felem s ->
Stack unit
(requires fun h ->
live h p /\ live h text /\ live h acc /\
disjoint acc p /\ disjoint acc text /\
felem_fits h acc (3, 3, 3, 3, 3) /\
F32xN.load_precompute_r_post #(width s) h p)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
F32xN.load_precompute_r_post #(width s) h1 p /\
feval h1 acc ==
LSeq.repeat_blocks_f #uint8 #(Vec.elem (width s))
(v bs) (as_seq h0 text) (Vec.poly1305_update_nblocks #(width s) (feval h0 (gsub p 10ul 5ul))) (v nb) (v i) (feval h0 acc))
let poly1305_update_multi_f #s pre bs nb len text i acc=
assert ((v i + 1) * v bs <= v nb * v bs);
let block = sub #_ #_ #len text (i *! bs) bs in
let h1 = ST.get () in
as_seq_gsub h1 text (i *! bs) bs;
poly1305_update_nblocks #s pre block acc
#push-options "--max_fuel 1"
inline_for_extraction noextract
val poly1305_update_multi_loop:
#s:field_spec
-> bs:size_t{v bs == width s * S.size_block}
-> len:size_t{v len % v (blocklen s) == 0}
-> text:lbuffer uint8 len
-> pre:precomp_r s
-> acc:felem s ->
Stack unit
(requires fun h ->
live h pre /\ live h acc /\ live h text /\
disjoint acc text /\ disjoint acc pre /\
felem_fits h acc (3, 3, 3, 3, 3) /\
F32xN.load_precompute_r_post #(width s) h pre)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
F32xN.load_precompute_r_post #(width s) h1 pre /\
feval h1 acc == LSeq.repeat_blocks_multi #uint8 #(Vec.elem (width s)) (v bs) (as_seq h0 text)
(Vec.poly1305_update_nblocks (feval h0 (gsub pre 10ul 5ul))) (feval h0 acc))
let poly1305_update_multi_loop #s bs len text pre acc =
let nb = len /. bs in
let h0 = ST.get () in
LSeq.lemma_repeat_blocks_multi #uint8 #(Vec.elem (width s)) (v bs) (as_seq h0 text)
(Vec.poly1305_update_nblocks #(width s) (feval h0 (gsub pre 10ul 5ul))) (feval h0 acc);
[@ inline_let]
let spec_fh h0 =
LSeq.repeat_blocks_f (v bs) (as_seq h0 text)
(Vec.poly1305_update_nblocks #(width s) (feval h0 (gsub pre 10ul 5ul))) (v nb) in
[@ inline_let]
let inv h (i:nat{i <= v nb}) =
modifies1 acc h0 h /\
live h pre /\ live h text /\ live h acc /\
disjoint acc pre /\ disjoint acc text /\
felem_fits h acc (3, 3, 3, 3, 3) /\
F32xN.load_precompute_r_post #(width s) h pre /\
feval h acc == Lib.LoopCombinators.repeati i (spec_fh h0) (feval h0 acc) in
Lib.Loops.for (size 0) nb inv
(fun i ->
Lib.LoopCombinators.unfold_repeati (v nb) (spec_fh h0) (feval h0 acc) (v i);
poly1305_update_multi_f #s pre bs nb len text i acc)
#pop-options
#push-options "--z3rlimit 350"
inline_for_extraction noextract
val poly1305_update_multi:
#s:field_spec
-> len:size_t{0 < v len /\ v len % v (blocklen s) == 0}
-> text:lbuffer uint8 len
-> pre:precomp_r s
-> acc:felem s ->
Stack unit
(requires fun h ->
live h pre /\ live h acc /\ live h text /\
disjoint acc text /\ disjoint acc pre /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.load_precompute_r_post #(width s) h pre)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (2, 2, 2, 2, 2) /\
(feval h1 acc).[0] ==
Vec.poly1305_update_multi #(width s) (as_seq h0 text)
(feval h0 acc).[0] (feval h0 (gsub pre 0ul 5ul)).[0])
let poly1305_update_multi #s len text pre acc =
let h0 = ST.get () in
assert_norm (v 10ul + v 5ul <= v 20ul);
assert (feval h0 (gsub pre 10ul 5ul) == Vec.compute_rw #(width s) ((feval h0 (gsub pre 0ul 5ul)).[0]));
let bs = blocklen s in
//assert (v bs == width s * S.size_block);
let text0 = sub text 0ul bs in
load_acc #s acc text0;
let len1 = len -! bs in
let text1 = sub text bs len1 in
poly1305_update_multi_loop #s bs len1 text1 pre acc;
fmul_rn_normalize acc pre
#pop-options
inline_for_extraction noextract
val poly1305_update_vec:
#s:field_spec
-> len:size_t
-> text:lbuffer uint8 len
-> pre:precomp_r s
-> acc:felem s ->
Stack unit
(requires fun h ->
live h text /\ live h acc /\ live h pre /\
disjoint acc text /\ disjoint acc pre /\
felem_fits h acc (2, 2, 2, 2, 2) /\
F32xN.load_precompute_r_post #(width s) h pre)
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (2, 2, 2, 2, 2) /\
(feval h1 acc).[0] ==
Vec.poly1305_update_vec #(width s) (as_seq h0 text) (feval h0 acc).[0] (feval h0 (gsub pre 0ul 5ul)).[0])
let poly1305_update_vec #s len text pre acc =
let sz_block = blocklen s in
FStar.Math.Lemmas.multiply_fractions (v len) (v sz_block);
let len0 = (len /. sz_block) *! sz_block in
let t0 = sub text 0ul len0 in
FStar.Math.Lemmas.multiple_modulo_lemma (v (len /. sz_block)) (v (blocklen s));
if len0 >. 0ul then poly1305_update_multi len0 t0 pre acc;
let len1 = len -! len0 in
let t1 = sub text len0 len1 in
poly1305_update_scalar #s len1 t1 pre acc
inline_for_extraction noextract
val poly1305_update32: poly1305_update_st M32
let poly1305_update32 ctx len text =
let pre = get_precomp_r ctx in
let acc = get_acc ctx in
poly1305_update_scalar #M32 len text pre acc
inline_for_extraction noextract
val poly1305_update_128_256: #s:field_spec { s = M128 || s = M256 } -> poly1305_update_st s
let poly1305_update_128_256 #s ctx len text =
let pre = get_precomp_r ctx in
let acc = get_acc ctx in
let h0 = ST.get () in
poly1305_update_vec #s len text pre acc;
let h1 = ST.get () in
Equiv.poly1305_update_vec_lemma #(width s) (as_seq h0 text) (feval h0 acc).[0] (feval h0 (gsub pre 0ul 5ul)).[0]
inline_for_extraction noextract
[@ Meta.Attribute.specialize ]
let poly1305_update #s =
match s with
| M32 -> poly1305_update32
| _ -> poly1305_update_128_256 #s
#set-options "--z3rlimit 150"
[@ Meta.Attribute.specialize ]
let poly1305_finish #s tag key ctx =
let acc = get_acc ctx in
let ks = sub key 16ul 16ul in
let h0 = ST.get () in
reduce_felem acc;
let h1 = ST.get () in
assert ((fas_nat h1 acc).[0] == (feval h0 acc).[0]);
let (f10, f11) = uints64_from_felem_le acc in
assert (v f11 * pow2 64 + v f10 == (fas_nat h1 acc).[0] % pow2 128);
let (f20, f21) = uints64_from_bytes_le ks in
assert (v f21 * pow2 64 + v f20 == BSeq.nat_from_bytes_le (as_seq h0 ks));
let (f30, f31) = mod_add128 (f10, f11) (f20, f21) in
assert (v f31 * pow2 64 + v f30 ==
((fas_nat h1 acc).[0] % pow2 128 + BSeq.nat_from_bytes_le (as_seq h0 ks)) % pow2 128);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (fas_nat h1 acc).[0] (BSeq.nat_from_bytes_le (as_seq h0 ks)) (pow2 128);
uints64_to_bytes_le tag f30 f31
noextract | {
"checked_file": "/",
"dependencies": [
"Spec.Poly1305.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Equiv.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Bignum128.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Poly1305.Field32xN",
"short_module": "F32xN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Equiv",
"short_module": "Equiv"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": true,
"full_module": "Spec.Poly1305",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Bignum128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Poly1305",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Poly1305.poly1305_mac_st s | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Poly1305.Fields.field_spec",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.buffer",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Poly1305.poly1305_finish",
"Hacl.Impl.Poly1305.poly1305_update",
"Hacl.Impl.Poly1305.poly1305_init",
"Lib.Buffer.lbuffer_t",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.IntTypes.add",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Hacl.Impl.Poly1305.Fields.limb",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Impl.Poly1305.Fields.nlimb",
"Hacl.Impl.Poly1305.Fields.precomplen",
"Hacl.Impl.Poly1305.Fields.limb_zero",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | false | false | let poly1305_mac #s output input input_len key =
| push_frame ();
let ctx = create (nlimb s +! precomplen s) (limb_zero s) in
poly1305_init #s ctx key;
poly1305_update #s ctx input_len input;
poly1305_finish #s output key ctx;
pop_frame () | false |
LL.fst | LL.get_n1_stexn | val get_n1_stexn: unit
-> StExn nat
(requires fun n -> n > 0)
(ensures
fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1) | val get_n1_stexn: unit
-> StExn nat
(requires fun n -> n > 0)
(ensures
fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1) | let get_n1_stexn (_:unit)
: StExn nat
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= STEXN?.reflect (fun n -> get_n1_exn n) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 317,
"start_col": 0,
"start_line": 310
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n)))
inline_for_extraction
let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n)
sub_effect PURE ~> STEXN = lift_pure_stexn
effect StExn (a:Type) (pre:nat -> Type0) (post:nat -> option (a & nat) -> Type0) =
STEXN a (fun p n -> pre n /\ (forall r. post n r ==> p r))
(*** Example using the STEXN effect ***) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> LL.StExn Prims.nat | LL.StExn | [] | [] | [
"Prims.unit",
"Prims.nat",
"LL.get_n1_exn",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Pervasives.Native.option",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition"
] | [] | false | true | false | false | false | let get_n1_stexn (_: unit)
: StExn nat
(requires fun n -> n > 0)
(ensures
fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1) =
| STEXN?.reflect (fun n -> get_n1_exn n) | false |
LL.fst | LL.main | val main : Prims.unit | let main =
let nopt = test_st () in
FStar.IO.print_string (match nopt with
| None -> FStar.All.failwith "Unexpected none"
| Some n -> FStar.Printf.sprintf "Output: %d\n" n) | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 360,
"start_col": 0,
"start_line": 356
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n)))
inline_for_extraction
let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n)
sub_effect PURE ~> STEXN = lift_pure_stexn
effect StExn (a:Type) (pre:nat -> Type0) (post:nat -> option (a & nat) -> Type0) =
STEXN a (fun p n -> pre n /\ (forall r. post n r ==> p r))
(*** Example using the STEXN effect ***)
inline_for_extraction
let get_n1_stexn (_:unit)
: StExn nat
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= STEXN?.reflect (fun n -> get_n1_exn n)
/// get_flt function in the STEXN effect that hides the state also
inline_for_extraction
let get_flt_stexn (_:unit)
: StExn flt
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= let x = get_n1_stexn () in
let y = get_n1_stexn () in
let z = get_n1_stexn () in
{ n1 = x; n2 = y; n3 = z}
/// And now we can reify the effect to reveal a spec in terms of PURE
let get_flt_stexn_reified (n:nat)
: Pure (option (flt * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= reify (reify (get_flt_stexn ()) n) ()
/// An extraction test
let test () : Exn int True (fun _ -> True)
= 4
let test_st () : Pure (option int) True (fun _ -> True)
= reify (test ()) () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.unit | Prims.Tot | [
"total"
] | [] | [
"FStar.IO.print_string",
"Prims.unit",
"Prims.string",
"FStar.All.failwith",
"Prims.int",
"FStar.Printf.sprintf",
"FStar.Pervasives.Native.option",
"LL.test_st"
] | [] | false | false | false | true | false | let main =
| let nopt = test_st () in
FStar.IO.print_string (match nopt with
| None -> FStar.All.failwith "Unexpected none"
| Some n -> FStar.Printf.sprintf "Output: %d\n" n) | false |
|
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.heaps_match | val heaps_match (bs:Seq.seq buffer_info) (mt:memtaint) (h1 h2:vale_heap) (id:heaplet_id) : prop0 | val heaps_match (bs:Seq.seq buffer_info) (mt:memtaint) (h1 h2:vale_heap) (id:heaplet_id) : prop0 | let heaps_match bs mt h1 h2 id =
forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> (
let Mkbuffer_info t b hid tn _ = Seq.index bs i in
hid == id ==>
buffer_as_seq h1 b == buffer_as_seq h2 b /\
buffer_addr b h1 == buffer_addr b h2 /\
buffer_readable h1 b == buffer_readable h2 b /\
(t == TUInt64 ==> (valid_taint_buf64 b h1 mt tn <==> valid_taint_buf64 b h2 mt tn)) /\
(t == TUInt128 ==> (valid_taint_buf128 b h1 mt tn <==> valid_taint_buf128 b h2 mt tn)) /\
(forall (i:int).{:pattern (buffer_read b i h1) \/ (buffer_read b i h2)}
buffer_read b i h1 == buffer_read b i h2)) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 768,
"start_col": 0,
"start_line": 758
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu
#restart-solver
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) =
exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (
let bi = Seq.index layout.vl_buffers n in
t == bi.bi_typ /\
b == bi.bi_buffer /\
(write ==> bi.bi_mutable == Mutable) /\
hid == bi.bi_heaplet)
[@"opaque_to_smt"]
let valid_layout_buffer_id t b layout h_id write =
match h_id with
| None -> True
| Some hid ->
layout.vl_inner.vl_heaplets_initialized /\
valid_layout_data_buffer t b layout.vl_inner hid write
let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) =
h.ih.IB.ptrs == hi.ih.IB.ptrs /\
Map.domain h.mh == Map.domain hi.mh /\
(forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i}
Set.mem i owns ==>
Set.mem i (Map.domain h.mh) /\
Map.sel h.mh i == Map.sel hi.mh i /\
True
) /\
True
// heaplet state matches heap state
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) =
let t = bi.bi_typ in
let hid = bi.bi_heaplet in
let hi = Map16.get hs hid in
let b = bi.bi_buffer in
let owns = owners hid in
(bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\
buffer_readable h b /\
buffer_as_seq hi b == buffer_as_seq h b /\
(valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\
(forall (i:int).{:pattern Set.mem i owns}
buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\
True
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) =
let bs = layout.vl_buffers in
modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)}
layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)
) /\
(forall (i:heaplet_id).{:pattern (Map16.sel hs i)}
inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\
True
let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized
let mem_inv h =
h.vf_heap.heapletId == None /\
inv_heaplet_ids h.vf_heaplets /\
(if h.vf_layout.vl_inner.vl_heaplets_initialized
then
inv_heaplets h.vf_layout.vl_inner h.vf_heap
h.vf_heaplets h.vf_layout.vl_taint
else
h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap
)
let layout_heaplets_initialized layout = layout.vl_heaplets_initialized
let layout_old_heap layout = layout.vl_old_heap
let layout_modifies_loc layout = layout.vl_mod_loc
let layout_buffers layout = layout.vl_buffers | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
mt: Vale.PPC64LE.Memory.memtaint ->
h1: Vale.Arch.HeapImpl.vale_heap ->
h2: Vale.Arch.HeapImpl.vale_heap ->
id: Vale.Arch.HeapImpl.heaplet_id
-> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.PPC64LE.Memory.memtaint",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.mutability",
"Prims.eq2",
"Prims.l_and",
"Vale.PPC64LE.Memory.base_typ_as_vale_type",
"Vale.PPC64LE.Memory.buffer_as_seq",
"Prims.int",
"Vale.PPC64LE.Memory.buffer_addr",
"Vale.Def.Prop_s.prop0",
"Vale.PPC64LE.Memory.buffer_readable",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.l_iff",
"Vale.PPC64LE.Memory.valid_taint_buf64",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.PPC64LE.Memory.valid_taint_buf128",
"Vale.PPC64LE.Memory.buffer_read",
"Prims.logical",
"FStar.Seq.Base.index"
] | [] | false | false | false | true | false | let heaps_match bs mt h1 h2 id =
| forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==>
(let Mkbuffer_info t b hid tn _ = Seq.index bs i in
hid == id ==>
buffer_as_seq h1 b == buffer_as_seq h2 b /\ buffer_addr b h1 == buffer_addr b h2 /\
buffer_readable h1 b == buffer_readable h2 b /\
(t == TUInt64 ==> (valid_taint_buf64 b h1 mt tn <==> valid_taint_buf64 b h2 mt tn)) /\
(t == TUInt128 ==> (valid_taint_buf128 b h1 mt tn <==> valid_taint_buf128 b h2 mt tn)) /\
(forall (i: int). {:pattern (buffer_read b i h1)\/(buffer_read b i h2)}
buffer_read b i h1 == buffer_read b i h2)) | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.write_taint_lemma | val write_taint_lemma
(i: nat)
(mem: IB.interop_heap)
(ts: (b8 -> GTot taint))
(b: b8)
(accu: memtaint)
: Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j: int). {:pattern accu.[ j ]}
mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b))
(ensures
(let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j. {:pattern m.[ j ]}
addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\
(forall j. {:pattern m.[ j ]}
j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ])))
(decreases %[DV.length (get_downview b.bsrc) - i]) | val write_taint_lemma
(i: nat)
(mem: IB.interop_heap)
(ts: (b8 -> GTot taint))
(b: b8)
(accu: memtaint)
: Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j: int). {:pattern accu.[ j ]}
mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b))
(ensures
(let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j. {:pattern m.[ j ]}
addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\
(forall j. {:pattern m.[ j ]}
j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ])))
(decreases %[DV.length (get_downview b.bsrc) - i]) | let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 659,
"start_col": 0,
"start_line": 637
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Prims.nat ->
mem: Vale.Interop.Heap_s.interop_heap ->
ts: (_: Vale.PPC64LE.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint) ->
b: Vale.PPC64LE.Memory.b8 ->
accu: Vale.PPC64LE.Memory.memtaint
-> FStar.Pervasives.Lemma
(requires
i <= LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\
(forall (j: Prims.int). {:pattern accu.[ j ]}
InteropHeap?.addrs mem b <= j /\ j < InteropHeap?.addrs mem b + i ==> accu.[ j ] = ts b)
)
(ensures
(let m = Vale.Interop.Base.write_taint i mem ts b accu in
let addr = InteropHeap?.addrs mem b in
(forall (j: Prims.int). {:pattern m.[ j ]}
addr <= j /\
j <
addr +
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) ==>
m.[ j ] = ts b) /\
(forall (j: Prims.int). {:pattern m.[ j ]}
j < addr \/
j >=
addr +
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) ==>
m.[ j ] == accu.[ j ])))
(decreases
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) - i) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"Vale.Interop.Heap_s.interop_heap",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapTypes_s.taint",
"Vale.PPC64LE.Memory.memtaint",
"Prims.op_GreaterThanOrEqual",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.bool",
"Vale.PPC64LE.Memory.write_taint_lemma",
"Prims.op_Addition",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Prims.int",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.eq2",
"Vale.PPC64LE.Memory.op_String_Access",
"FStar.Set.equal",
"FStar.Map.domain",
"FStar.Set.complement",
"FStar.Set.empty",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Interop.Base.write_taint",
"FStar.Map.t",
"Vale.PPC64LE.Memory.op_String_Assignment",
"Vale.Def.Words_s.nat64",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Prims.op_Equality",
"Prims.squash",
"Prims.l_or",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec write_taint_lemma
(i: nat)
(mem: IB.interop_heap)
(ts: (b8 -> GTot taint))
(b: b8)
(accu: memtaint)
: Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j: int). {:pattern accu.[ j ]}
mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b))
(ensures
(let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j. {:pattern m.[ j ]}
addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\
(forall j. {:pattern m.[ j ]}
j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ])))
(decreases %[DV.length (get_downview b.bsrc) - i]) =
| let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc)
then ()
else
let new_accu = accu.[ addr + i ] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j. {:pattern m.[ j ]} addr <= j /\ j < addr + i + 1 ==> new_accu.[ j ] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu | false |
Vale.PPC64LE.Memory.fst | Vale.PPC64LE.Memory.valid_memtaint | val valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint))
: Lemma (requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) | val valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint))
: Lemma (requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) | let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma
(requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 142,
"end_line": 677,
"start_col": 0,
"start_line": 662
} | module Vale.PPC64LE.Memory
include Vale.Interop.Types
friend Vale.Arch.Heap
open Vale.Def.Opaque_s
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
open Vale.Interop.Base
module IB = Vale.Interop.Base
module I = Vale.Interop
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module M = LowStar.Modifies
open LowStar.ModifiesPat
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
module H = FStar.Heap
module S = Vale.Arch.MachineHeap_s
#reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let b8 = IB.b8
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
let get_heaplet_id h =
h.heapletId
let tuint8 = UInt8.t
let tuint16 = UInt16.t
let tuint32 = UInt32.t
let tuint64 = UInt64.t
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t =
match t with
| TUInt8 -> UInt8.uint_to_t v
| TUInt16 -> UInt16.uint_to_t v
| TUInt32 -> UInt32.uint_to_t v
| TUInt64 -> UInt64.uint_to_t v
| TUInt128 -> v
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t =
match t with
| TUInt8 -> UInt8.v v
| TUInt16 -> UInt16.v v
| TUInt32 -> UInt32.v v
| TUInt64 -> UInt64.v v
| TUInt128 -> v
let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma
(ensures v_to_typ t (v_of_typ t v) == v)
[SMTPat (v_to_typ t (v_of_typ t v))]
=
()
let uint8_view = Vale.Interop.Views.up_view8
let uint16_view = Vale.Interop.Views.up_view16
let uint32_view = Vale.Interop.Views.up_view32
let uint64_view = Vale.Interop.Views.up_view64
let uint128_view = Vale.Interop.Views.up_view128
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) =
match t with
| TUInt8 -> uint8_view
| TUInt16 -> uint16_view
| TUInt32 -> uint32_view
| TUInt64 -> uint64_view
| TUInt128 -> uint128_view
let buffer_as_seq #t h b =
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in
Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
let buffer_writeable #t b = b.writeable
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
let loc = M.loc
let loc_none = M.loc_none
let loc_union = M.loc_union
let loc_buffer #t b = M.loc_buffer b.bsrc
let loc_disjoint = M.loc_disjoint
let loc_includes = M.loc_includes
let modifies s h h' =
M.modifies s (_ih h).hs (_ih h').hs /\
h.heapletId == h'.heapletId /\
(_ih h).ptrs == (_ih h').ptrs /\
(_ih h).addrs == (_ih h').addrs /\
HST.equal_domains (_ih h).hs (_ih h').hs
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
open FStar.Mul
#set-options "--z3rlimit 20"
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma
(requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
(ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
let open Vale.Def.Words.Seq_s in
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
Vale.Interop.Views.get64_reveal ();
S.get_heap_val64_reveal ();
Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
let index_helper (x y:int) (heap:S.machine_heap) : Lemma
(requires x == y)
(ensures heap.[x] == heap.[y])
=
()
let index_mul_helper (addr i n j:int) : Lemma
(addr + (i * n + j) == addr + n * i + j) =
()
#set-options "--max_fuel 0 --max_ifuel 0"
let index64_get_heap_val64
(h:vale_heap)
(b:buffer64{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap)
=
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
let ptr = buffer_addr b h + scale8 i in
let s = DV.as_seq (_ih h).hs db in
let t = TUInt64 in
let addr = buffer_addr b h in
UV.length_eq ub;
UV.as_seq_sel (_ih h).hs ub i;
UV.get_sel (_ih h).hs ub i;
let s' = Seq.slice s (i*8) (i*8 + 8) in
let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]);
Seq.lemma_index_slice s (i*8) (i*8+8) j;
assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]);
index_mul_helper addr i 8 j;
()
in Classical.forall_intro aux;
index64_heap_aux s' heap ptr
#set-options "--z3rlimit 50"
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Lib.Seqs_s
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma
(requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j]))
(ensures Vale.Interop.Views.get128 s == Mkfour
(S.get_heap_val32 ptr heap)
(S.get_heap_val32 (ptr+4) heap)
(S.get_heap_val32 (ptr+8) heap)
(S.get_heap_val32 (ptr+12) heap)) =
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
S.get_heap_val32_reveal ();
Vale.Interop.Views.get128_reveal ();
Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
let index128_get_heap_val128
(h:vale_heap)
(b:buffer128{List.memP b (_ih h).ptrs})
(heap:S.machine_heap{IB.correct_down (_ih h) heap})
(i:nat{i < buffer_length b})
: Lemma
(ensures (
let addr = buffer_addr b h in
Seq.index (buffer_as_seq h b) i ==
Mkfour
(S.get_heap_val32 (addr + scale16 i) heap)
(S.get_heap_val32 (addr + scale16 i+4) heap)
(S.get_heap_val32 (addr + scale16 i+8) heap)
(S.get_heap_val32 (addr + scale16 i +12) heap)
))
=
let db = get_downview b.bsrc in
let vb = UV.mk_buffer db uint128_view in
let ptr = buffer_addr b h + scale16 i in
let s = DV.as_seq (_ih h).hs db in
let addr = buffer_addr b h in
UV.length_eq vb;
UV.as_seq_sel (_ih h).hs vb i;
UV.get_sel (_ih h).hs vb i;
let sl = Seq.slice s (i*16) (i*16+16) in
let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) =
assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]);
Seq.lemma_index_slice s (i*16) (i*16+16) j;
assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]);
index_mul_helper addr i 16 j
in Classical.forall_intro aux;
index128_get_heap_val128_aux sl ptr heap
let modifies_goal_directed s h1 h2 = modifies s h1 h2
let lemma_modifies_goal_directed s h1 h2 = ()
let buffer_length_buffer_as_seq #t h b = ()
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma
(requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
(ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
=
let db = get_downview b.bsrc in
let rec aux (i:nat{i <= buffer_length b}) : Lemma
(requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\
(Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db)))
(ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j))
(decreases %[(buffer_length b) - i]) =
if i = buffer_length b then ()
else (
let bv = UV.mk_buffer db (uint_view t) in
UV.get_sel (_ih h1).hs bv i;
UV.get_sel (_ih h2).hs bv i;
UV.as_seq_sel (_ih h1).hs bv i;
UV.as_seq_sel (_ih h2).hs bv i;
aux (i+1)
)
in aux 0
let modifies_buffer_elim #t1 b p h h' =
let db = get_downview b.bsrc in
lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs;
same_underlying_seq h h' b;
assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
let modifies_buffer_addr #t b p h h' = ()
let modifies_buffer_readable #t b p h h' = ()
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
let loc_includes_refl s = M.loc_includes_refl s
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
let loc_includes_none s = M.loc_includes_none s
let modifies_refl s h = M.modifies_refl s (_ih h).hs
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
()
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
let default_of_typ (t:base_typ) : base_typ_as_vale_type t =
allow_inversion base_typ;
match t with
| TUInt8 -> 0
| TUInt16 -> 0
| TUInt32 -> 0
| TUInt64 -> 0
| TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
let buffer_read #t b i h =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i
let seq_upd
(#b:_)
(h:HS.mem)
(vb:UV.buffer b{UV.live h vb})
(i:nat{i < UV.length vb})
(x:b)
: Lemma
(Seq.equal
(Seq.upd (UV.as_seq h vb) i x)
(UV.as_seq (UV.upd h vb i x) vb))
=
let old_s = UV.as_seq h vb in
let new_s = UV.as_seq (UV.upd h vb i x) vb in
let upd_s = Seq.upd old_s i x in
let rec aux (k:nat) : Lemma
(requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j)))
(ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j))
(decreases %[(Seq.length upd_s) - k]) =
if k = Seq.length upd_s then ()
else begin
UV.sel_upd vb i k x h;
UV.as_seq_sel h vb k;
UV.as_seq_sel (UV.upd h vb i x) vb k;
aux (k+1)
end
in aux 0
let buffer_write #t b i v h =
if i < 0 || i >= buffer_length b then h else
begin
let view = uint_view t in
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db view in
UV.upd_modifies (_ih h).hs bv i (v_of_typ t v);
UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v);
let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in
let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in
let mh' = Vale.Interop.down_mem ih' in
let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in
seq_upd (_ih h).hs bv i (v_of_typ t v);
assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v));
h'
end
unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
// Checks if address addr corresponds to one of the elements of buffer ptr
let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool
(requires True)
(ensures fun b -> not b <==>
(forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==>
addr <> (buffer_addr ptr h) + scale_t t i))
=
let n = buffer_length ptr in
let base = buffer_addr ptr h in
let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==>
addr <> base + scale_t t j)})
(decreases %[n-i]) =
if i >= n then false
else if addr = base + scale_t t i then true
else aux (i+1)
in aux 0
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) =
exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat
(requires valid_offset t n base addr i)
(ensures fun j -> base + scale_t t j == addr)
(decreases %[n - i])
=
if base + scale_t t i = addr then i
else get_addr_in_ptr t n base addr (i + 1)
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h
let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable
#set-options "--max_fuel 1 --max_ifuel 1"
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b ->
b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)}
List.memP x ps /\ valid_buffer t addr x h))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o ->
match o with
| None -> not (valid_mem_aux t addr ps h)
| Some a -> valid_buffer t addr a h /\ List.memP a ps)
=
match ps with
| [] -> None
| a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs)
(ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
=
match ps with
| [] -> ()
| a::q -> find_valid_buffer_aux_ps t addr q h1 h2
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma
(requires (_ih h1).ptrs == (_ih h2).ptrs)
(ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
=
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma
(ensures (
match find_valid_buffer t addr h with
| None -> True
| Some a ->
let base = buffer_addr a h in
valid_offset t (buffer_length a) base addr 0
))
=
()
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool
(requires sub_list ps (_ih h).ptrs)
(ensures fun b -> b <==>
(exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x}
List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t))
(requires sub_list ps (_ih h).ptrs)
(ensures fun o -> (
match o with
| None -> not (writeable_mem_aux t addr ps h)
| Some a -> writeable_buffer t addr a h /\ List.memP a ps
))
=
match ps with
| [] -> None
| a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h
let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) =
match find_valid_buffer t addr h with
| None -> default_of_typ t
| Some a ->
let base = buffer_addr a h in
buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h
let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h
let length_t_eq (t:base_typ) (b:buffer t) :
Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.length_eq ub;
assert (buffer_length b == DV.length db / (view_n t));
FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t)
(requires valid_mem t ptr h)
(ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
=
Some?.v (find_valid_buffer t ptr h)
#reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20"
let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma
(requires valid_mem t ptr h)
(ensures (
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
load_mem t ptr h == buffer_read #t b i h
))
=
()
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap
(requires True)
(ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
=
match find_writeable_buffer t addr h with
| None -> h
| Some a ->
let base = buffer_addr a h in
buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h
let store_buffer_write
(t:base_typ)
(ptr:int)
(v:base_typ_as_vale_type t)
(h:vale_heap{writeable_mem t ptr h})
: Lemma
(ensures (
let b = Some?.v (find_writeable_buffer t ptr h) in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_mem t ptr v h == buffer_write b i v h
))
=
()
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h
let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h
let lemma_valid_mem64 b i h = ()
let lemma_writeable_mem64 b i h = ()
let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h
)
=
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let view = uint_view t in
let addr = buffer_addr b h + scale_t t i in
match find_writeable_buffer t addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_load_mem64 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale8 i in
let view = uint64_view in
match find_valid_buffer TUInt64 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
let lemma_valid_mem128 b i h = ()
let lemma_writeable_mem128 b i h = ()
let lemma_load_mem128 b i h =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
let addr = buffer_addr b h + scale16 i in
let view = uint128_view in
match find_valid_buffer TUInt128 addr h with
| None -> ()
| Some a ->
let da = get_downview a.bsrc in
let db = get_downview b.bsrc in
UV.length_eq (UV.mk_buffer da view);
UV.length_eq (UV.mk_buffer db view);
opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b);
assert (a == b)
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
open Vale.X64.Machine_s
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
let addr = (_ih h).addrs b in
(forall (i:int).{:pattern (mt.[i])}
addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
let valid_taint_buf #t b h mt tn =
valid_taint_b8 b h mt tn
let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma
(requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn)
(ensures memTaint.[(_ih mem).addrs b + i] == tn)
=
()
let lemma_valid_taint64 b memTaint mem i t =
length_t_eq (TUInt64) b;
let ptr = buffer_addr b mem + scale8 i in
let aux (i':nat) : Lemma
(requires i' >= ptr /\ i' < ptr + 8)
(ensures memTaint.[i'] == t) =
let extra = scale8 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let lemma_valid_taint128 b memTaint mem i t =
length_t_eq (TUInt128) b;
let ptr = buffer_addr b mem + scale16 i in
let aux i' : Lemma
(requires i' >= ptr /\ i' < ptr + 16)
(ensures memTaint.[i'] == t) =
let extra = scale16 i + i' - ptr in
assert (i' == (_ih mem).addrs b + extra);
apply_taint_buf b mem memTaint t extra
in
Classical.forall_intro (Classical.move_requires aux)
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma
(requires modifies (loc_buffer b) mem0 mem1 /\
(forall p. Map.sel memT0 p == Map.sel memT1 p))
(ensures memT0 == memT1) =
assert (Map.equal memT0 memT1)
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
let modifies_valid_taint #t b p h h' mt tn =
let dv = get_downview b.bsrc in
let imp_left () : Lemma
(requires valid_taint_buf b h mt tn)
(ensures valid_taint_buf b h' mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) =
apply_taint_buf b h mt tn i
in Classical.forall_intro aux
in let imp_right () : Lemma
(requires valid_taint_buf b h' mt tn)
(ensures valid_taint_buf b h mt tn) =
let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) =
apply_taint_buf b h' mt tn i
in Classical.forall_intro aux
in
(Classical.move_requires imp_left());
(Classical.move_requires imp_right())
#set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let modifies_same_heaplet_id l h1 h2 =
()
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) =
forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma
(requires
i <= DV.length (get_downview b.bsrc) /\
(forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b)
)
(ensures (
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
(forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==>
m.[j] = ts b) /\
(forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==>
m.[j] == accu.[j])))
(decreases %[DV.length (get_downview b.bsrc) - i])
=
let m = IB.write_taint i mem ts b accu in
let addr = mem.addrs b in
if i >= DV.length (get_downview b.bsrc) then ()
else
let new_accu = accu.[addr+i] <- ts b in
assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu);
assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty));
assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b);
write_taint_lemma (i + 1) mem ts b new_accu | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Types.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.Memory.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
mem: Vale.Arch.HeapImpl.vale_heap ->
ps: Prims.list Vale.PPC64LE.Memory.b8 ->
ts: (_: Vale.PPC64LE.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint)
-> FStar.Pervasives.Lemma (requires Vale.Interop.Heap_s.list_disjoint_or_eq ps)
(ensures
Vale.PPC64LE.Memory.valid_taint_bufs mem
(Vale.Interop.Base.create_memtaint (Vale.Arch.HeapImpl._ih mem) ps ts)
ps
ts) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Prims.list",
"Vale.PPC64LE.Memory.b8",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Def.Opaque_s.opaque_assert",
"Vale.Interop.Types.b8",
"Prims.logical",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Vale.Interop.Heap_s.list_disjoint_or_eq_def",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Heap_s.disjoint_or_eq_b8",
"Prims.unit",
"Vale.PPC64LE.Memory.write_taint_lemma",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.Base.create_memtaint",
"Prims._assert",
"Prims.eq2",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Interop.Base.write_taint",
"Vale.PPC64LE.Memory.valid_memtaint",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Words_s.nat64",
"Vale.Interop.Types.addr_map_pred",
"Prims.squash",
"Vale.PPC64LE.Memory.valid_taint_bufs",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint))
: Lemma (requires IB.list_disjoint_or_eq ps)
(ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) =
| FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred;
match ps with
| [] -> ()
| b :: q ->
assert (List.memP b ps);
assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps);
opaque_assert (`%list_disjoint_or_eq)
list_disjoint_or_eq
list_disjoint_or_eq_def
(IB.list_disjoint_or_eq q);
valid_memtaint mem q ts;
assert (IB.create_memtaint (_ih mem) ps ts ==
IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts));
write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts);
opaque_assert (`%list_disjoint_or_eq)
list_disjoint_or_eq
list_disjoint_or_eq_def
(forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) | false |
LL.fst | LL.get_flt_stexn | val get_flt_stexn: unit
-> StExn flt
(requires fun n -> n > 0)
(ensures
fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n) | val get_flt_stexn: unit
-> StExn flt
(requires fun n -> n > 0)
(ensures
fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n) | let get_flt_stexn (_:unit)
: StExn flt
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n)
= let x = get_n1_stexn () in
let y = get_n1_stexn () in
let z = get_n1_stexn () in
{ n1 = x; n2 = y; n3 = z} | {
"file_name": "examples/layeredeffects/LL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 333,
"start_col": 0,
"start_line": 323
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LL
/// An example of layering exception over PURE, and then a state over it
///
/// See also parsing/FlightsStExn.fst where the underlying effect is HyperStack.ST
(*** Define an exception effect over PURE ***)
/// Type of pre- and postcondition
type epre_t = Type0
type epost_t (a:Type) = option a -> Type0
/// wp has a refinement for monotonicity -- we should handle it more uniformly in the typechecker
type ewp_t0 (a:Type) = epost_t a -> epre_t
unfold
let ewp_monotonic (#a:Type) (wp:ewp_t0 a) : Type0 =
forall p q. (forall x. p x ==> q x) ==>
(wp p ==> wp q)
type ewp_t (a:Type) = wp:ewp_t0 a{ewp_monotonic wp}
/// Now the underlying representation of the layered effect
///
/// It's just a thunked option-returning computation
open FStar.Monotonic.Pure
type erepr (a:Type) (wp:ewp_t a) = unit -> PURE (option a) (as_pure_wp wp)
/// Defining the effect combinators
///
/// We require return, bind, subcomp, and if_then_else
inline_for_extraction
let ereturn (a:Type) (x:a)
: erepr a (fun p -> p (Some x))
= fun _ -> Some x
inline_for_extraction
let ebind (a:Type) (b:Type)
(wp_f:ewp_t a) (wp_g:a -> ewp_t b)
(f:erepr a wp_f) (g:(x:a -> erepr b (wp_g x)))
: erepr b
(fun (p:epost_t b) ->
wp_f (fun (r:option a) ->
match r with
| None -> p None
| Some x -> wp_g x p))
= fun _ ->
let r = f () in
match r with
| None -> None
| Some x -> g x ()
inline_for_extraction
let esubcomp (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f)
: Pure (erepr a wp_g)
(requires forall p. wp_g p ==> wp_f p)
(ensures fun _ -> True)
= f
inline_for_extraction
let eif_then_else (a:Type)
(wp_f:ewp_t a) (wp_g:ewp_t a)
(f:erepr a wp_f) (g:erepr a wp_g)
(p:bool)
: Type
= erepr a
(fun post ->
(p ==> wp_f post) /\
((~ p) ==> wp_g post))
/// The effect definition
total reifiable reflectable
effect {
EXN (a:Type) (_:ewp_t a)
with {repr = erepr;
return = ereturn;
bind = ebind;
subcomp = esubcomp;
if_then_else = eif_then_else}
}
/// Lift from PURE to EXN
unfold
let lift_pure_wp (#a:Type) (wp:pure_wp a) : ewp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p -> wp (fun x -> p (Some x))
inline_for_extraction
let lift_pure_exn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: erepr a (lift_pure_wp wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ -> Some (f ())
sub_effect PURE ~> EXN = lift_pure_exn
/// Shorthand for hoare-style specs
effect Exn (a:Type) (pre:Type0) (post:option a -> Type0) =
EXN a (fun p -> pre /\ (forall r. post r ==> p r))
(*** Some examples using the EXN effect ***)
assume val get_n1
: n:nat ->
Pure (option (nat * nat))
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
type flt = {
n1 : nat;
n2 : nat;
n3 : i:nat{n1 > 0 /\ n2 = n1 + 1 /\ i = n2 + 1}
}
/// This is how the get_flt function would look like in the PURE effect with nested pattern matching
let get_flt (n:nat)
: Pure (option flt)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let r = get_n1 n in
match r with
| None -> None
| Some (x, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (y, n) ->
let r = get_n1 n in
match r with
| None -> None
| Some (z, _) -> Some ({ n1 = x; n2 = y; n3 = z })
/// Now we implement it in the EXN effect
///
/// First, inject get_n1 into the EXN effect
inline_for_extraction
let get_n1_exn (n:nat)
: Exn (nat * nat)
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= EXN?.reflect (fun _ -> get_n1 n)
/// Now we can implement get_flt in the EXN effect using get_n1_exn
inline_for_extraction
let get_flt_exn (n:nat)
: Exn flt
(requires n > 0)
(ensures fun r ->
match r with
| None -> True
| Some flt -> flt.n1 == n)
= let x, n = get_n1_exn n in
let y, n = get_n1_exn n in
let z, _ = get_n1_exn n in
{ n1 = x; n2 = y; n3 = z}
/// This is good, but note that there is still some state passing (`n`)
///
/// We can hide that behind an effect too
(*** A state effect layered on top of EXN ***)
type pre_t = nat -> Type0
type post_t (a:Type) = option (a & nat) -> Type0
type wp_t0 (a:Type) = post_t a -> pre_t
unfold
let wpt_monotonic (#a:Type) (wp:wp_t0 a) =
forall p q. (forall r. p r ==> q r) ==>
(forall n. wp p n ==> wp q n)
type wp_t (a:Type) = wp:wp_t0 a{wpt_monotonic wp}
type repr (a:Type) (wp:wp_t a) =
n:nat -> EXN (a & nat) (fun p -> wp p n)
inline_for_extraction
let return (a:Type) (x:a)
: repr a (fun p n -> p (Some (x, n)))
= fun n -> (x, n)
unfold
let post_a (a:Type) (b:Type) (wp_g:a -> wp_t b) (p:post_t b) : post_t a =
fun r ->
match r with
| None -> p None
| Some r -> wp_g (Mktuple2?._1 r) p (Mktuple2?._2 r)
unfold
let bind_wp (a:Type) (b:Type) (wp_f:wp_t a) (wp_g:a -> wp_t b) : wp_t b
= fun p n0 ->
wp_f (fun r ->
match r with
| None -> p None
| Some (x, n1) -> (wp_g x) p n1) n0
inline_for_extraction
let bind (a:Type) (b:Type)
(wp_f:wp_t a) (wp_g:a -> wp_t b)
(f:repr a wp_f) (g:(x:a -> repr b (wp_g x)))
: repr b (bind_wp a b wp_f wp_g)
= fun n ->
let r = f n in
g (fst r) (snd r)
inline_for_extraction
let subcomp (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f)
: Pure (repr a wp_g)
(requires forall p n. wp_g p n ==> wp_f p n)
(ensures fun _ -> True)
= f
inline_for_extraction
let if_then_else (a:Type)
(wp_f:wp_t a) (wp_g:wp_t a)
(f:repr a wp_f) (g:repr a wp_g)
(p:bool)
: Type
= repr a
(fun post n ->
(p ==> wp_f post n) /\
((~ p) ==> wp_g post n))
total reifiable reflectable
effect {
STEXN (a:Type) (wp:wp_t a)
with {repr; return; bind; subcomp; if_then_else}
}
unfold
let lift_pure_wp_stexn (#a:Type) (wp:pure_wp a) : wp_t a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun p n -> wp (fun x -> p (Some (x, n)))
inline_for_extraction
let lift_pure_stexn (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a (lift_pure_wp_stexn wp)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun n -> (f (), n)
sub_effect PURE ~> STEXN = lift_pure_stexn
effect StExn (a:Type) (pre:nat -> Type0) (post:nat -> option (a & nat) -> Type0) =
STEXN a (fun p n -> pre n /\ (forall r. post n r ==> p r))
(*** Example using the STEXN effect ***)
inline_for_extraction
let get_n1_stexn (_:unit)
: StExn nat
(requires fun n -> n > 0)
(ensures fun n r ->
match r with
| None -> True
| Some (n1, n2) -> n1 == n /\ n2 == n + 1)
= STEXN?.reflect (fun n -> get_n1_exn n)
/// get_flt function in the STEXN effect that hides the state also | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "LL.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> LL.StExn LL.flt | LL.StExn | [] | [] | [
"Prims.unit",
"LL.Mkflt",
"LL.flt",
"Prims.nat",
"LL.get_n1_stexn",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.l_True",
"Prims.eq2",
"LL.__proj__Mkflt__item__n1"
] | [] | false | true | false | false | false | let get_flt_stexn (_: unit)
: StExn flt
(requires fun n -> n > 0)
(ensures
fun n r ->
match r with
| None -> True
| Some (flt, _) -> flt.n1 == n) =
| let x = get_n1_stexn () in
let y = get_n1_stexn () in
let z = get_n1_stexn () in
{ n1 = x; n2 = y; n3 = z } | false |
Spec.SHA3.Incremental.fst | Spec.SHA3.Incremental.suffix | val suffix : a: Spec.Hash.Definitions.keccak_alg
-> b: Lib.IntTypes.byte_t{Lib.IntTypes.v b == 0x1f \/ Lib.IntTypes.v b == 0x06} | let suffix (a: keccak_alg) = if is_shake a then byte 0x1f else byte 0x06 | {
"file_name": "specs/lemmas/Spec.SHA3.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | module Spec.SHA3.Incremental
module S = FStar.Seq
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Incremental.Definitions
open Spec.Hash.Lemmas
friend Spec.Agile.Hash
open FStar.Mul
module Loops = Lib.LoopCombinators
module UpdateMulti = Lib.UpdateMulti
open Lib.IntTypes
#set-options "--fuel 0 --ifuel 0 --z3rlimit 200"
let update_is_update_multi (a:keccak_alg) (inp:bytes{S.length inp == block_length a}) (s:words_state a)
: Lemma (Spec.SHA3.absorb_inner (rate a/8) inp s == update_multi a s () inp)
= let rateInBytes = rate a/8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
let bs = block_length a in
let f' = Lib.Sequence.repeat_blocks_f bs inp f 1 in
assert (bs == rateInBytes);
calc (==) {
update_multi a s () inp;
(==) { }
Lib.Sequence.repeat_blocks_multi #_ #(words_state a) rateInBytes inp f s;
(==) { Lib.Sequence.lemma_repeat_blocks_multi #_ #(words_state a) bs inp f s }
(let len = S.length inp in
let nb = len / bs in
Loops.repeati #(words_state a) nb (Lib.Sequence.repeat_blocks_f bs inp f nb) s);
(==) {
Loops.unfold_repeati 1 f' s 0;
Loops.eq_repeati0 1 f' s }
f' 0 s;
(==) { assert (Seq.slice inp (0 * bs) (0 * bs + bs) `S.equal` inp) }
f inp s;
} | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fst.checked",
"Spec.Agile.Hash.fst.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA3.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.UpdateMulti",
"short_module": "UpdateMulti"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Incremental.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Incremental.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.SHA3",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA3",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.keccak_alg
-> b: Lib.IntTypes.byte_t{Lib.IntTypes.v b == 0x1f \/ Lib.IntTypes.v b == 0x06} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.keccak_alg",
"Spec.Hash.Definitions.is_shake",
"Lib.IntTypes.byte",
"Prims.bool",
"Lib.IntTypes.byte_t",
"Prims.l_or",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.range",
"Lib.IntTypes.U8",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB"
] | [] | false | false | false | false | false | let suffix (a: keccak_alg) =
| if is_shake a then byte 0x1f else byte 0x06 | false |
|
Vale.X64.InsAes.fsti | Vale.X64.InsAes.va_wp_Pclmulqdq | val va_wp_Pclmulqdq
(dst src: va_operand_xmm)
(dstHi srcHi: bool)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Pclmulqdq
(dst src: va_operand_xmm)
(dstHi srcHi: bool)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32
(va_if dstHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 dst)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))) (Vale.Math.Poly2.Bits_s.of_double32
(va_if srcHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src))))) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.X64.InsAes.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 44,
"start_col": 0,
"start_line": 35
} | module Vale.X64.InsAes
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.QuickCode
open Vale.X64.CPU_Features_s
//-- Pclmulqdq
val va_code_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool -> Tot
va_code
val va_codegen_success_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool ->
srcHi:bool -> Tot va_pbool
val va_lemma_Pclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src:va_operand_xmm -> dstHi:bool -> srcHi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Pclmulqdq dst src dstHi srcHi) va_s0 /\ va_is_dst_xmm
dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if dstHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 dst) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))
(Vale.Math.Poly2.Bits_s.of_double32 (if srcHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.InsAes.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Instructions_s",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Taint_Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"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.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_xmm ->
src: Vale.X64.Decls.va_operand_xmm ->
dstHi: Prims.bool ->
srcHi: Prims.bool ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_xmm",
"Prims.bool",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Vale.X64.Decls.va_is_dst_xmm",
"Vale.X64.Decls.va_is_src_xmm",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.pclmulqdq_enabled",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_xmm",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"Vale.X64.Decls.va_eval_xmm",
"Vale.Math.Poly2.Bits_s.to_quad32",
"Vale.Math.Poly2_s.mul",
"Vale.Math.Poly2.Bits_s.of_double32",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.double32",
"Vale.Arch.Types.quad32_double_hi",
"Prims.l_not",
"Vale.Arch.Types.quad32_double_lo",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_xmm"
] | [] | false | false | false | true | true | let va_wp_Pclmulqdq
(dst src: va_operand_xmm)
(dstHi srcHi: bool)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled /\
(forall (va_x_dst: va_value_xmm) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32 (va_if
dstHi
(fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 dst))
(fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst))))
(Vale.Math.Poly2.Bits_s.of_double32 (va_if srcHi
(fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src))
(fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src))))) ==>
va_k va_sM (()))) | false |
Vale.X64.InsAes.fsti | Vale.X64.InsAes.va_wp_AESNI_enc | val va_wp_AESNI_enc (dst src: va_operand_xmm) (va_s0: va_state) (va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AESNI_enc (dst src: va_operand_xmm) (va_s0: va_state) (va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AESNI_enc (dst:va_operand_xmm) (src:va_operand_xmm) (va_s0:va_state) (va_k:(va_state ->
unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes
(Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst)))) (va_eval_xmm va_s0 src) ==> va_k va_sM
(()))) | {
"file_name": "obj/Vale.X64.InsAes.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 131,
"start_col": 0,
"start_line": 124
} | module Vale.X64.InsAes
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.QuickCode
open Vale.X64.CPU_Features_s
//-- Pclmulqdq
val va_code_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool -> Tot
va_code
val va_codegen_success_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool ->
srcHi:bool -> Tot va_pbool
val va_lemma_Pclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src:va_operand_xmm -> dstHi:bool -> srcHi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Pclmulqdq dst src dstHi srcHi) va_s0 /\ va_is_dst_xmm
dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if dstHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 dst) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))
(Vale.Math.Poly2.Bits_s.of_double32 (if srcHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32
(va_if dstHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 dst)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))) (Vale.Math.Poly2.Bits_s.of_double32
(va_if srcHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src))))) ==> va_k va_sM (())))
val va_wpProof_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool ->
va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Pclmulqdq dst src dstHi srcHi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Pclmulqdq dst src dstHi srcHi)
([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool) :
(va_quickCode unit (va_code_Pclmulqdq dst src dstHi srcHi)) =
(va_QProc (va_code_Pclmulqdq dst src dstHi srcHi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_Pclmulqdq dst src dstHi srcHi) (va_wpProof_Pclmulqdq dst src dstHi srcHi))
//--
//-- VPclmulqdq
val va_code_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> Tot va_code
val va_codegen_success_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm ->
src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool -> Tot va_pbool
val va_lemma_VPclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src1:va_operand_xmm -> src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) va_s0 /\
va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if src1Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src1) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1)))
(Vale.Math.Poly2.Bits_s.of_double32 (if src2Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src2)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm) (src1Hi:bool)
(src2Hi:bool) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled) /\ (forall (va_x_dst:va_value_xmm)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32
(Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32 (va_if src1Hi (fun _ ->
Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src1)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1))))
(Vale.Math.Poly2.Bits_s.of_double32 (va_if src2Hi (fun _ -> Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2)) (fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0
src2))))) ==> va_k va_sM (())))
val va_wpProof_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_VPclmulqdq dst src1 src2 src1Hi src2Hi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_VPclmulqdq dst src1 src2 src1Hi
src2Hi) ([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm)
(src1Hi:bool) (src2Hi:bool) : (va_quickCode unit (va_code_VPclmulqdq dst src1 src2 src1Hi
src2Hi)) =
(va_QProc (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_VPclmulqdq dst src1 src2 src1Hi src2Hi) (va_wpProof_VPclmulqdq dst src1 src2 src1Hi
src2Hi))
//--
//-- AESNI_enc
val va_code_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_code
val va_codegen_success_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_pbool
val va_lemma_AESNI_enc : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm -> src:va_operand_xmm
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AESNI_enc dst src) va_s0 /\ va_is_dst_xmm dst va_s0 /\
va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE
(Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst))))
(va_eval_xmm va_s0 src) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM
(va_update_operand_xmm dst va_sM va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.InsAes.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Instructions_s",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Taint_Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"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.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_xmm ->
src: Vale.X64.Decls.va_operand_xmm ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_xmm",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Vale.X64.Decls.va_is_dst_xmm",
"Vale.X64.Decls.va_is_src_xmm",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_xmm",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"Vale.X64.Decls.va_eval_xmm",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_s.mix_columns_LE",
"Vale.AES.AES_common_s.sub_bytes",
"Vale.AES.AES_s.shift_rows_LE",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_xmm"
] | [] | false | false | false | true | true | let va_wp_AESNI_enc (dst src: va_operand_xmm) (va_s0: va_state) (va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled /\
(forall (va_x_dst: va_value_xmm) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE
(va_eval_xmm va_s0 dst))))
(va_eval_xmm va_s0 src) ==>
va_k va_sM (()))) | false |
Vale.X64.InsAes.fsti | Vale.X64.InsAes.va_wp_VPclmulqdq | val va_wp_VPclmulqdq
(dst src1 src2: va_operand_xmm)
(src1Hi src2Hi: bool)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_VPclmulqdq
(dst src1 src2: va_operand_xmm)
(src1Hi src2Hi: bool)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm) (src1Hi:bool)
(src2Hi:bool) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled) /\ (forall (va_x_dst:va_value_xmm)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32
(Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32 (va_if src1Hi (fun _ ->
Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src1)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1))))
(Vale.Math.Poly2.Bits_s.of_double32 (va_if src2Hi (fun _ -> Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2)) (fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0
src2))))) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.X64.InsAes.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 92,
"start_col": 0,
"start_line": 81
} | module Vale.X64.InsAes
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.QuickCode
open Vale.X64.CPU_Features_s
//-- Pclmulqdq
val va_code_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool -> Tot
va_code
val va_codegen_success_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool ->
srcHi:bool -> Tot va_pbool
val va_lemma_Pclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src:va_operand_xmm -> dstHi:bool -> srcHi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Pclmulqdq dst src dstHi srcHi) va_s0 /\ va_is_dst_xmm
dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if dstHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 dst) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))
(Vale.Math.Poly2.Bits_s.of_double32 (if srcHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32
(va_if dstHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 dst)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))) (Vale.Math.Poly2.Bits_s.of_double32
(va_if srcHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src))))) ==> va_k va_sM (())))
val va_wpProof_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool ->
va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Pclmulqdq dst src dstHi srcHi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Pclmulqdq dst src dstHi srcHi)
([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool) :
(va_quickCode unit (va_code_Pclmulqdq dst src dstHi srcHi)) =
(va_QProc (va_code_Pclmulqdq dst src dstHi srcHi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_Pclmulqdq dst src dstHi srcHi) (va_wpProof_Pclmulqdq dst src dstHi srcHi))
//--
//-- VPclmulqdq
val va_code_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> Tot va_code
val va_codegen_success_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm ->
src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool -> Tot va_pbool
val va_lemma_VPclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src1:va_operand_xmm -> src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) va_s0 /\
va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if src1Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src1) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1)))
(Vale.Math.Poly2.Bits_s.of_double32 (if src2Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src2)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.InsAes.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Instructions_s",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Taint_Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"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.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_xmm ->
src1: Vale.X64.Decls.va_operand_xmm ->
src2: Vale.X64.Decls.va_operand_xmm ->
src1Hi: Prims.bool ->
src2Hi: Prims.bool ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_xmm",
"Prims.bool",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Vale.X64.Decls.va_is_dst_xmm",
"Vale.X64.Decls.va_is_src_xmm",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.pclmulqdq_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_xmm",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"Vale.X64.Decls.va_eval_xmm",
"Vale.Math.Poly2.Bits_s.to_quad32",
"Vale.Math.Poly2_s.mul",
"Vale.Math.Poly2.Bits_s.of_double32",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.double32",
"Vale.Arch.Types.quad32_double_hi",
"Prims.l_not",
"Vale.Arch.Types.quad32_double_lo",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_xmm"
] | [] | false | false | false | true | true | let va_wp_VPclmulqdq
(dst src1 src2: va_operand_xmm)
(src1Hi src2Hi: bool)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok va_s0 /\
(pclmulqdq_enabled /\ avx_enabled) /\
(forall (va_x_dst: va_value_xmm) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32 (va_if
src1Hi
(fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src1))
(fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1))))
(Vale.Math.Poly2.Bits_s.of_double32 (va_if src2Hi
(fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src2))
(fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src2))))) ==>
va_k va_sM (()))) | false |
Vale.X64.InsAes.fsti | Vale.X64.InsAes.va_wp_VAESNI_enc | val va_wp_VAESNI_enc
(dst src1 src2: va_operand_xmm)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_VAESNI_enc
(dst src1 src2: va_operand_xmm)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_VAESNI_enc (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (aesni_enabled /\ avx_enabled) /\ (forall (va_x_dst:va_value_xmm)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor
(Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE
(va_eval_xmm va_s0 src1)))) (va_eval_xmm va_s0 src2) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.X64.InsAes.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 172,
"start_col": 0,
"start_line": 165
} | module Vale.X64.InsAes
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.QuickCode
open Vale.X64.CPU_Features_s
//-- Pclmulqdq
val va_code_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool -> Tot
va_code
val va_codegen_success_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool ->
srcHi:bool -> Tot va_pbool
val va_lemma_Pclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src:va_operand_xmm -> dstHi:bool -> srcHi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Pclmulqdq dst src dstHi srcHi) va_s0 /\ va_is_dst_xmm
dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if dstHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 dst) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))
(Vale.Math.Poly2.Bits_s.of_double32 (if srcHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32
(va_if dstHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 dst)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))) (Vale.Math.Poly2.Bits_s.of_double32
(va_if srcHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src))))) ==> va_k va_sM (())))
val va_wpProof_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool ->
va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Pclmulqdq dst src dstHi srcHi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Pclmulqdq dst src dstHi srcHi)
([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool) :
(va_quickCode unit (va_code_Pclmulqdq dst src dstHi srcHi)) =
(va_QProc (va_code_Pclmulqdq dst src dstHi srcHi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_Pclmulqdq dst src dstHi srcHi) (va_wpProof_Pclmulqdq dst src dstHi srcHi))
//--
//-- VPclmulqdq
val va_code_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> Tot va_code
val va_codegen_success_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm ->
src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool -> Tot va_pbool
val va_lemma_VPclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src1:va_operand_xmm -> src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) va_s0 /\
va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if src1Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src1) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1)))
(Vale.Math.Poly2.Bits_s.of_double32 (if src2Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src2)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm) (src1Hi:bool)
(src2Hi:bool) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled) /\ (forall (va_x_dst:va_value_xmm)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32
(Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32 (va_if src1Hi (fun _ ->
Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src1)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1))))
(Vale.Math.Poly2.Bits_s.of_double32 (va_if src2Hi (fun _ -> Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2)) (fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0
src2))))) ==> va_k va_sM (())))
val va_wpProof_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_VPclmulqdq dst src1 src2 src1Hi src2Hi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_VPclmulqdq dst src1 src2 src1Hi
src2Hi) ([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm)
(src1Hi:bool) (src2Hi:bool) : (va_quickCode unit (va_code_VPclmulqdq dst src1 src2 src1Hi
src2Hi)) =
(va_QProc (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_VPclmulqdq dst src1 src2 src1Hi src2Hi) (va_wpProof_VPclmulqdq dst src1 src2 src1Hi
src2Hi))
//--
//-- AESNI_enc
val va_code_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_code
val va_codegen_success_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_pbool
val va_lemma_AESNI_enc : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm -> src:va_operand_xmm
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AESNI_enc dst src) va_s0 /\ va_is_dst_xmm dst va_s0 /\
va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE
(Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst))))
(va_eval_xmm va_s0 src) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM
(va_update_operand_xmm dst va_sM va_s0)))))
[@ va_qattr]
let va_wp_AESNI_enc (dst:va_operand_xmm) (src:va_operand_xmm) (va_s0:va_state) (va_k:(va_state ->
unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes
(Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst)))) (va_eval_xmm va_s0 src) ==> va_k va_sM
(())))
val va_wpProof_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AESNI_enc dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AESNI_enc dst src) ([va_Mod_flags;
va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AESNI_enc (dst:va_operand_xmm) (src:va_operand_xmm) : (va_quickCode unit
(va_code_AESNI_enc dst src)) =
(va_QProc (va_code_AESNI_enc dst src) ([va_Mod_flags; va_mod_xmm dst]) (va_wp_AESNI_enc dst src)
(va_wpProof_AESNI_enc dst src))
//--
//-- VAESNI_enc
val va_code_VAESNI_enc : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm -> Tot
va_code
val va_codegen_success_VAESNI_enc : dst:va_operand_xmm -> src1:va_operand_xmm ->
src2:va_operand_xmm -> Tot va_pbool
val va_lemma_VAESNI_enc : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src1:va_operand_xmm -> src2:va_operand_xmm
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_VAESNI_enc dst src1 src2) va_s0 /\ va_is_dst_xmm dst
va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ avx_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE
(Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 src1))))
(va_eval_xmm va_s0 src2) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM
(va_update_operand_xmm dst va_sM va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.InsAes.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Instructions_s",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Taint_Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"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.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_xmm ->
src1: Vale.X64.Decls.va_operand_xmm ->
src2: Vale.X64.Decls.va_operand_xmm ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_xmm",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Vale.X64.Decls.va_is_dst_xmm",
"Vale.X64.Decls.va_is_src_xmm",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_xmm",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"Vale.X64.Decls.va_eval_xmm",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_s.mix_columns_LE",
"Vale.AES.AES_common_s.sub_bytes",
"Vale.AES.AES_s.shift_rows_LE",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_xmm"
] | [] | false | false | false | true | true | let va_wp_VAESNI_enc
(dst src1 src2: va_operand_xmm)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ avx_enabled) /\
(forall (va_x_dst: va_value_xmm) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE
(va_eval_xmm va_s0 src1))))
(va_eval_xmm va_s0 src2) ==>
va_k va_sM (()))) | false |
Vale.X64.InsAes.fsti | Vale.X64.InsAes.va_wp_AESNI_enc_last | val va_wp_AESNI_enc_last
(dst src: va_operand_xmm)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AESNI_enc_last
(dst src: va_operand_xmm)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AESNI_enc_last (dst:va_operand_xmm) (src:va_operand_xmm) (va_s0:va_state) (va_k:(va_state
-> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE
(va_eval_xmm va_s0 dst))) (va_eval_xmm va_s0 src) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.X64.InsAes.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 208,
"start_col": 0,
"start_line": 202
} | module Vale.X64.InsAes
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.QuickCode
open Vale.X64.CPU_Features_s
//-- Pclmulqdq
val va_code_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool -> Tot
va_code
val va_codegen_success_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool ->
srcHi:bool -> Tot va_pbool
val va_lemma_Pclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src:va_operand_xmm -> dstHi:bool -> srcHi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Pclmulqdq dst src dstHi srcHi) va_s0 /\ va_is_dst_xmm
dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if dstHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 dst) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))
(Vale.Math.Poly2.Bits_s.of_double32 (if srcHi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ pclmulqdq_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32
(va_if dstHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 dst)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 dst)))) (Vale.Math.Poly2.Bits_s.of_double32
(va_if srcHi (fun _ -> Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src))))) ==> va_k va_sM (())))
val va_wpProof_Pclmulqdq : dst:va_operand_xmm -> src:va_operand_xmm -> dstHi:bool -> srcHi:bool ->
va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Pclmulqdq dst src dstHi srcHi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Pclmulqdq dst src dstHi srcHi)
([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Pclmulqdq (dst:va_operand_xmm) (src:va_operand_xmm) (dstHi:bool) (srcHi:bool) :
(va_quickCode unit (va_code_Pclmulqdq dst src dstHi srcHi)) =
(va_QProc (va_code_Pclmulqdq dst src dstHi srcHi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_Pclmulqdq dst src dstHi srcHi) (va_wpProof_Pclmulqdq dst src dstHi srcHi))
//--
//-- VPclmulqdq
val va_code_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> Tot va_code
val va_codegen_success_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm ->
src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool -> Tot va_pbool
val va_lemma_VPclmulqdq : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src1:va_operand_xmm -> src2:va_operand_xmm -> src1Hi:bool -> src2Hi:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) va_s0 /\
va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul
(Vale.Math.Poly2.Bits_s.of_double32 (if src1Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src1) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1)))
(Vale.Math.Poly2.Bits_s.of_double32 (if src2Hi then Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2) else Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src2)))) /\
va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm) (src1Hi:bool)
(src2Hi:bool) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (pclmulqdq_enabled /\ avx_enabled) /\ (forall (va_x_dst:va_value_xmm)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32
(Vale.Math.Poly2_s.mul (Vale.Math.Poly2.Bits_s.of_double32 (va_if src1Hi (fun _ ->
Vale.Arch.Types.quad32_double_hi (va_eval_xmm va_s0 src1)) (fun _ ->
Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0 src1))))
(Vale.Math.Poly2.Bits_s.of_double32 (va_if src2Hi (fun _ -> Vale.Arch.Types.quad32_double_hi
(va_eval_xmm va_s0 src2)) (fun _ -> Vale.Arch.Types.quad32_double_lo (va_eval_xmm va_s0
src2))))) ==> va_k va_sM (())))
val va_wpProof_VPclmulqdq : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
src1Hi:bool -> src2Hi:bool -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_VPclmulqdq dst src1 src2 src1Hi src2Hi va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_VPclmulqdq dst src1 src2 src1Hi
src2Hi) ([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_VPclmulqdq (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm)
(src1Hi:bool) (src2Hi:bool) : (va_quickCode unit (va_code_VPclmulqdq dst src1 src2 src1Hi
src2Hi)) =
(va_QProc (va_code_VPclmulqdq dst src1 src2 src1Hi src2Hi) ([va_Mod_flags; va_mod_xmm dst])
(va_wp_VPclmulqdq dst src1 src2 src1Hi src2Hi) (va_wpProof_VPclmulqdq dst src1 src2 src1Hi
src2Hi))
//--
//-- AESNI_enc
val va_code_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_code
val va_codegen_success_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_pbool
val va_lemma_AESNI_enc : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm -> src:va_operand_xmm
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AESNI_enc dst src) va_s0 /\ va_is_dst_xmm dst va_s0 /\
va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE
(Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst))))
(va_eval_xmm va_s0 src) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM
(va_update_operand_xmm dst va_sM va_s0)))))
[@ va_qattr]
let va_wp_AESNI_enc (dst:va_operand_xmm) (src:va_operand_xmm) (va_s0:va_state) (va_k:(va_state ->
unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled /\
(forall (va_x_dst:va_value_xmm) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_operand_xmm dst va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes
(Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst)))) (va_eval_xmm va_s0 src) ==> va_k va_sM
(())))
val va_wpProof_AESNI_enc : dst:va_operand_xmm -> src:va_operand_xmm -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AESNI_enc dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AESNI_enc dst src) ([va_Mod_flags;
va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AESNI_enc (dst:va_operand_xmm) (src:va_operand_xmm) : (va_quickCode unit
(va_code_AESNI_enc dst src)) =
(va_QProc (va_code_AESNI_enc dst src) ([va_Mod_flags; va_mod_xmm dst]) (va_wp_AESNI_enc dst src)
(va_wpProof_AESNI_enc dst src))
//--
//-- VAESNI_enc
val va_code_VAESNI_enc : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm -> Tot
va_code
val va_codegen_success_VAESNI_enc : dst:va_operand_xmm -> src1:va_operand_xmm ->
src2:va_operand_xmm -> Tot va_pbool
val va_lemma_VAESNI_enc : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src1:va_operand_xmm -> src2:va_operand_xmm
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_VAESNI_enc dst src1 src2) va_s0 /\ va_is_dst_xmm dst
va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ avx_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor (Vale.AES.AES_s.mix_columns_LE
(Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 src1))))
(va_eval_xmm va_s0 src2) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_ok va_sM
(va_update_operand_xmm dst va_sM va_s0)))))
[@ va_qattr]
let va_wp_VAESNI_enc (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src1 va_s0 /\ va_is_src_xmm src2 va_s0 /\ va_get_ok
va_s0 /\ (aesni_enabled /\ avx_enabled) /\ (forall (va_x_dst:va_value_xmm)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor
(Vale.AES.AES_s.mix_columns_LE (Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE
(va_eval_xmm va_s0 src1)))) (va_eval_xmm va_s0 src2) ==> va_k va_sM (())))
val va_wpProof_VAESNI_enc : dst:va_operand_xmm -> src1:va_operand_xmm -> src2:va_operand_xmm ->
va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_VAESNI_enc dst src1 src2 va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_VAESNI_enc dst src1 src2)
([va_Mod_flags; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_VAESNI_enc (dst:va_operand_xmm) (src1:va_operand_xmm) (src2:va_operand_xmm) :
(va_quickCode unit (va_code_VAESNI_enc dst src1 src2)) =
(va_QProc (va_code_VAESNI_enc dst src1 src2) ([va_Mod_flags; va_mod_xmm dst]) (va_wp_VAESNI_enc
dst src1 src2) (va_wpProof_VAESNI_enc dst src1 src2))
//--
//-- AESNI_enc_last
val va_code_AESNI_enc_last : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_code
val va_codegen_success_AESNI_enc_last : dst:va_operand_xmm -> src:va_operand_xmm -> Tot va_pbool
val va_lemma_AESNI_enc_last : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm ->
src:va_operand_xmm
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AESNI_enc_last dst src) va_s0 /\ va_is_dst_xmm dst
va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_xmm va_sM dst == Vale.Def.Types_s.quad32_xor (Vale.AES.AES_common_s.sub_bytes
(Vale.AES.AES_s.shift_rows_LE (va_eval_xmm va_s0 dst))) (va_eval_xmm va_s0 src) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.InsAes.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Instructions_s",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Taint_Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"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.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_xmm ->
src: Vale.X64.Decls.va_operand_xmm ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_xmm",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Vale.X64.Decls.va_is_dst_xmm",
"Vale.X64.Decls.va_is_src_xmm",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_xmm",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"Vale.X64.Decls.va_eval_xmm",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_common_s.sub_bytes",
"Vale.AES.AES_s.shift_rows_LE",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_xmm"
] | [] | false | false | false | true | true | let va_wp_AESNI_enc_last
(dst src: va_operand_xmm)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_xmm dst va_s0 /\ va_is_src_xmm src va_s0 /\ va_get_ok va_s0 /\ aesni_enabled /\
(forall (va_x_dst: va_value_xmm) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_xmm dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_xmm va_sM dst ==
Vale.Def.Types_s.quad32_xor (Vale.AES.AES_common_s.sub_bytes (Vale.AES.AES_s.shift_rows_LE (va_eval_xmm
va_s0
dst)))
(va_eval_xmm va_s0 src) ==>
va_k va_sM (()))) | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.