file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.X64.Memory.fsti | Vale.X64.Memory.vuint32 | val vuint32 : Vale.Arch.HeapTypes_s.base_typ | let vuint32 = TUInt32 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 69,
"start_col": 7,
"start_line": 69
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Arch.HeapTypes_s.base_typ | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.TUInt32"
] | [] | false | false | false | true | false | let vuint32 =
| TUInt32 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.scale2 | val scale2 (index: int) : int | val scale2 (index: int) : int | let scale2 (index:int) : int = scale_by 2 index | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 42,
"start_col": 7,
"start_line": 42
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 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 | index: Prims.int -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Memory.scale_by"
] | [] | false | false | false | true | false | let scale2 (index: int) : int =
| scale_by 2 index | false |
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer32 | val buffer32 : Type0 | let buffer32 = buffer vuint32 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 75,
"start_col": 0,
"start_line": 75
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.vuint32"
] | [] | false | false | false | true | true | let buffer32 =
| buffer vuint32 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.vuint64 | val vuint64 : Vale.Arch.HeapTypes_s.base_typ | let vuint64 = TUInt64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 70,
"start_col": 7,
"start_line": 70
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Arch.HeapTypes_s.base_typ | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | false | false | false | true | false | let vuint64 =
| TUInt64 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.vuint128 | val vuint128 : Vale.Arch.HeapTypes_s.base_typ | let vuint128 = TUInt128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 71,
"start_col": 7,
"start_line": 71
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Arch.HeapTypes_s.base_typ | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | false | false | false | true | false | let vuint128 =
| TUInt128 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer8 | val buffer8 : Type0 | let buffer8 = buffer vuint8 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 73,
"start_col": 0,
"start_line": 73
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.vuint8"
] | [] | false | false | false | true | true | let buffer8 =
| buffer vuint8 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer64 | val buffer64 : Type0 | let buffer64 = buffer vuint64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 76,
"start_col": 0,
"start_line": 76
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.vuint64"
] | [] | false | false | false | true | true | let buffer64 =
| buffer vuint64 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer16 | val buffer16 : Type0 | let buffer16 = buffer vuint16 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.vuint16"
] | [] | false | false | false | true | true | let buffer16 =
| buffer vuint16 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.valid_taint_buf64 | val valid_taint_buf64 (b: buffer64) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | val valid_taint_buf64 (b: buffer64) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 311,
"start_col": 0,
"start_line": 310
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64 ->
h: Vale.X64.Memory.vale_heap ->
mt: Vale.X64.Memory.memtaint ->
tn: Vale.Arch.HeapTypes_s.taint
-> Prims.GTot Vale.Def.Prop_s.prop0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Memory.memtaint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Memory.valid_taint_buf",
"Vale.X64.Memory.vuint64",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | false | false | let valid_taint_buf64 (b: buffer64) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 =
| valid_taint_buf b h mt tn | false |
Vale.X64.Memory.fsti | Vale.X64.Memory.locs_disjoint | val locs_disjoint (ls: list loc) : prop0 | val locs_disjoint (ls: list loc) : prop0 | let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 83,
"start_col": 0,
"start_line": 82
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 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 | ls: Prims.list Vale.X64.Memory.loc -> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Memory.loc",
"FStar.BigOps.normal",
"FStar.BigOps.pairwise_and'",
"Prims.l_and",
"Vale.X64.Memory.loc_disjoint",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | true | false | let locs_disjoint (ls: list loc) : prop0 =
| BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls) | false |
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer128 | val buffer128 : Type0 | let buffer128 = buffer vuint128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 77,
"start_col": 0,
"start_line": 77
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.vuint128"
] | [] | false | false | false | true | true | let buffer128 =
| buffer vuint128 | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer_info_disjoint | val buffer_info_disjoint : bi1: Vale.Arch.HeapImpl.buffer_info -> bi2: Vale.Arch.HeapImpl.buffer_info -> Prims.logical | let buffer_info_disjoint (bi1 bi2:buffer_info) =
bi1.bi_typ =!= bi2.bi_typ \/ bi1.bi_heaplet =!= bi2.bi_heaplet ==>
loc_disjoint (loc_buffer bi1.bi_buffer) (loc_buffer bi2.bi_buffer) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 374,
"start_col": 0,
"start_line": 372
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
let valid_taint_buf128 (b:buffer128) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
val lemma_valid_taint64
(b:buffer64)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf64 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale8 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 8 ==> Map.sel memTaint i' == t))
val lemma_valid_taint128
(b:buffer128)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf128 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale16 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 16 ==> Map.sel memTaint i' == t))
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_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 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_same_heaplet_id (l:loc) (h1 h2:vale_heap) : Lemma
(requires modifies l h1 h2)
(ensures get_heaplet_id h1 == get_heaplet_id h2)
[SMTPat (modifies l h1 h2); SMTPat (get_heaplet_id h2)] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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 | bi1: Vale.Arch.HeapImpl.buffer_info -> bi2: Vale.Arch.HeapImpl.buffer_info -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.buffer_info",
"Prims.l_imp",
"Prims.l_or",
"Prims.l_not",
"Prims.eq2",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"Vale.X64.Memory.loc_disjoint",
"Vale.X64.Memory.loc_buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"Prims.logical"
] | [] | false | false | false | true | true | let buffer_info_disjoint (bi1 bi2: buffer_info) =
| bi1.bi_typ =!= bi2.bi_typ \/ bi1.bi_heaplet =!= bi2.bi_heaplet ==>
loc_disjoint (loc_buffer bi1.bi_buffer) (loc_buffer bi2.bi_buffer) | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.valid_layout_buffer | val valid_layout_buffer : b: Vale.X64.Memory.buffer t ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
h: Vale.X64.Memory.vale_heap ->
write: Prims.bool
-> Prims.logical | let valid_layout_buffer (#t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h:vale_heap) (write:bool) =
valid_layout_buffer_id t b layout (get_heaplet_id h) false /\
valid_layout_buffer_id t b layout (get_heaplet_id h) write | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 395,
"start_col": 0,
"start_line": 393
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
let valid_taint_buf128 (b:buffer128) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
val lemma_valid_taint64
(b:buffer64)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf64 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale8 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 8 ==> Map.sel memTaint i' == t))
val lemma_valid_taint128
(b:buffer128)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf128 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale16 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 16 ==> Map.sel memTaint i' == t))
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_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 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_same_heaplet_id (l:loc) (h1 h2:vale_heap) : Lemma
(requires modifies l h1 h2)
(ensures get_heaplet_id h1 == get_heaplet_id h2)
[SMTPat (modifies l h1 h2); SMTPat (get_heaplet_id h2)]
// Buffers in different heaplets are disjoint
let buffer_info_disjoint (bi1 bi2:buffer_info) =
bi1.bi_typ =!= bi2.bi_typ \/ bi1.bi_heaplet =!= bi2.bi_heaplet ==>
loc_disjoint (loc_buffer bi1.bi_buffer) (loc_buffer bi2.bi_buffer)
// Requirements for enabling heaplets
let init_heaplets_req (h:vale_heap) (bs:Seq.seq buffer_info) =
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
// Location containing all mutable buffers
let rec loc_mutable_buffers (buffers:list buffer_info) : GTot loc =
match buffers with
| [] -> loc_none
| [{bi_mutable = Mutable; bi_buffer = b}] -> loc_buffer b
| ({bi_mutable = Immutable})::t -> loc_mutable_buffers t
| ({bi_mutable = Mutable; bi_buffer = b})::t -> loc_union (loc_buffer b) (loc_mutable_buffers t)
// Buffer b belongs to heaplet h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer t ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
h: Vale.X64.Memory.vale_heap ->
write: Prims.bool
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.X64.Memory.vale_heap",
"Prims.bool",
"Prims.l_and",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.X64.Memory.get_heaplet_id",
"Prims.logical"
] | [] | false | false | false | false | true | let valid_layout_buffer
(#t: base_typ)
(b: buffer t)
(layout: vale_heap_layout)
(h: vale_heap)
(write: bool)
=
| valid_layout_buffer_id t b layout (get_heaplet_id h) false /\
valid_layout_buffer_id t b layout (get_heaplet_id h) write | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.valid_taint_buf128 | val valid_taint_buf128 (b: buffer128) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | val valid_taint_buf128 (b: buffer128) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | let valid_taint_buf128 (b:buffer128) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 313,
"start_col": 0,
"start_line": 312
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128 ->
h: Vale.X64.Memory.vale_heap ->
mt: Vale.X64.Memory.memtaint ->
tn: Vale.Arch.HeapTypes_s.taint
-> Prims.GTot Vale.Def.Prop_s.prop0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Memory.memtaint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Memory.valid_taint_buf",
"Vale.X64.Memory.vuint128",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | false | false | let valid_taint_buf128 (b: buffer128) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 =
| valid_taint_buf b h mt tn | false |
Vale.X64.Memory.fsti | Vale.X64.Memory.buffer_info_has_id | val buffer_info_has_id : bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
i: Prims.nat ->
id: Vale.X64.Memory.heaplet_id
-> Prims.logical | let buffer_info_has_id (bs:Seq.seq buffer_info) (i:nat) (id:heaplet_id) =
i < Seq.length bs /\ (Seq.index bs i).bi_heaplet == id | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 410,
"start_col": 0,
"start_line": 409
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
let valid_taint_buf128 (b:buffer128) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
val lemma_valid_taint64
(b:buffer64)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf64 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale8 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 8 ==> Map.sel memTaint i' == t))
val lemma_valid_taint128
(b:buffer128)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf128 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale16 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 16 ==> Map.sel memTaint i' == t))
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_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 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_same_heaplet_id (l:loc) (h1 h2:vale_heap) : Lemma
(requires modifies l h1 h2)
(ensures get_heaplet_id h1 == get_heaplet_id h2)
[SMTPat (modifies l h1 h2); SMTPat (get_heaplet_id h2)]
// Buffers in different heaplets are disjoint
let buffer_info_disjoint (bi1 bi2:buffer_info) =
bi1.bi_typ =!= bi2.bi_typ \/ bi1.bi_heaplet =!= bi2.bi_heaplet ==>
loc_disjoint (loc_buffer bi1.bi_buffer) (loc_buffer bi2.bi_buffer)
// Requirements for enabling heaplets
let init_heaplets_req (h:vale_heap) (bs:Seq.seq buffer_info) =
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
// Location containing all mutable buffers
let rec loc_mutable_buffers (buffers:list buffer_info) : GTot loc =
match buffers with
| [] -> loc_none
| [{bi_mutable = Mutable; bi_buffer = b}] -> loc_buffer b
| ({bi_mutable = Immutable})::t -> loc_mutable_buffers t
| ({bi_mutable = Mutable; bi_buffer = b})::t -> loc_union (loc_buffer b) (loc_mutable_buffers t)
// Buffer b belongs to heaplet h
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 (#t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h:vale_heap) (write:bool) =
valid_layout_buffer_id t b layout (get_heaplet_id h) false /\
valid_layout_buffer_id t b layout (get_heaplet_id h) write
// Initial memory state
val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0
// Invariant that is always true in Vale procedures
val mem_inv (h:vale_full_heap) : prop0
// Layout data
val layout_heaplets_initialized (layout:vale_heap_layout_inner) : bool
val layout_old_heap (layout:vale_heap_layout_inner) : vale_heap
val layout_modifies_loc (layout:vale_heap_layout_inner) : loc
val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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 |
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
i: Prims.nat ->
id: Vale.X64.Memory.heaplet_id
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.nat",
"Vale.X64.Memory.heaplet_id",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"FStar.Seq.Base.index",
"Prims.logical"
] | [] | false | false | false | true | true | let buffer_info_has_id (bs: Seq.seq buffer_info) (i: nat) (id: heaplet_id) =
| i < Seq.length bs /\ (Seq.index bs i).bi_heaplet == id | false |
|
Hacl.Impl.Load56.fst | Hacl.Impl.Load56.lemma_load_32_bytes | val lemma_load_32_bytes (k: lbytes 32) (b0 b1 b2 b3 b4: uint64)
: Lemma
(requires
v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\ v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\
v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\
v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\
v b4 == nat_from_bytes_le (Seq.slice k 28 32))
(ensures S56.as_nat5 (b0, b1, b2, b3, b4) == nat_from_bytes_le k) | val lemma_load_32_bytes (k: lbytes 32) (b0 b1 b2 b3 b4: uint64)
: Lemma
(requires
v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\ v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\
v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\
v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\
v b4 == nat_from_bytes_le (Seq.slice k 28 32))
(ensures S56.as_nat5 (b0, b1, b2, b3, b4) == nat_from_bytes_le k) | let lemma_load_32_bytes (k:lbytes 32) (b0 b1 b2 b3 b4:uint64) : Lemma
(requires
v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\
v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\
v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\
v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\
v b4 == nat_from_bytes_le (Seq.slice k 28 32))
(ensures S56.as_nat5 (b0, b1, b2, b3, b4) == nat_from_bytes_le k)
=
lemma_nat_from_bytes_le_append (Seq.slice k 0 7) (Seq.slice k 7 14);
lemma_nat_from_bytes_le_append (Seq.slice k 0 14) (Seq.slice k 14 21);
lemma_nat_from_bytes_le_append (Seq.slice k 0 21) (Seq.slice k 21 28);
lemma_nat_from_bytes_le_append (Seq.slice k 0 28) (Seq.slice k 28 32);
assert (Seq.append (Seq.slice k 0 7) (Seq.slice k 7 14) `Seq.equal` Seq.slice k 0 14);
assert (Seq.append (Seq.slice k 0 14) (Seq.slice k 14 21) `Seq.equal` Seq.slice k 0 21);
assert (Seq.append (Seq.slice k 0 21) (Seq.slice k 21 28) `Seq.equal` Seq.slice k 0 28);
assert (Seq.append (Seq.slice k 0 28) (Seq.slice k 28 32) `Seq.equal` k);
assert_norm (pow2 56 == 0x100000000000000);
assert_norm (pow2 112 == 0x10000000000000000000000000000);
assert_norm (pow2 168 == 0x1000000000000000000000000000000000000000000);
assert_norm (pow2 224 == 0x100000000000000000000000000000000000000000000000000000000) | {
"file_name": "code/ed25519/Hacl.Impl.Load56.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 212,
"start_col": 0,
"start_line": 192
} | module Hacl.Impl.Load56
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.ByteSequence
open Lib.Buffer
open Lib.ByteBuffer
module F56 = Hacl.Impl.BignumQ.Mul
module S56 = Hacl.Spec.BignumQ.Definitions
#reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
val hload56_le:
b:lbuffer uint8 64ul
-> off:size_t{v off <= 56} ->
Stack uint64
(requires fun h -> live h b)
(ensures fun h0 z h1 -> h0 == h1 /\
v z < 0x100000000000000 /\
v z == nat_from_bytes_le (Seq.slice (as_seq h0 b) (v off) (v off + 7))
)
let hload56_le b off =
let h0 = ST.get() in
let b8 = sub b off 8ul in
let z = uint_from_bytes_le b8 in
let z' = z &. u64 0xffffffffffffff in
assert_norm (0xffffffffffffff == pow2 56 - 1);
assert_norm (0x100000000000000 == pow2 56 );
calc (==) {
v z' <: nat;
(==) { }
v (z &. u64 0xffffffffffffff);
(==) { logand_spec z (u64 0xffffffffffffff) }
v z `logand_v` 0xffffffffffffff;
(==) { assert_norm(pow2 56 - 1 == 0xffffffffffffff); UInt.logand_mask (UInt.to_uint_t 64 (v z)) 56 }
(v z % pow2 56);
(==) { lemma_reveal_uint_to_bytes_le #U64 #SEC (as_seq h0 b8) }
nat_from_bytes_le (as_seq h0 b8) % pow2 56;
(==) { nat_from_intseq_le_slice_lemma (as_seq h0 b8) 7 }
(nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) +
pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) % pow2 56;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r
(nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7))
(pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8))
(pow2 56);
FStar.Math.Lemmas.swap_mul (pow2 (7 * 8)) (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8));
FStar.Math.Lemmas.cancel_mul_mod (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56) }
nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) <: nat;
};
assert (Seq.equal
(Seq.slice (as_seq h0 b) (v off) (v off + 7))
(Seq.slice (as_seq h0 b8) 0 7));
z'
let lemma_nat_from_bytes_le_append (k1 k2:bytes) : Lemma
(requires Seq.length k1 + Seq.length k2 <= max_size_t)
(ensures nat_from_bytes_le (Seq.append k1 k2) ==
nat_from_bytes_le k1 + pow2 (Seq.length k1 * 8) * nat_from_bytes_le k2) =
let k = Seq.append k1 k2 in
let n = Seq.length k1 + Seq.length k2 in
nat_from_intseq_le_slice_lemma #U8 #SEC #n k (Seq.length k1);
assert (k1 `Seq.equal` Seq.slice k 0 (Seq.length k1));
assert (k2 `Seq.equal` Seq.slice k (Seq.length k1) n)
#push-options "--z3rlimit 100"
let lemma_load_64_bytes (k:lbytes 64) (b0 b1 b2 b3 b4 b5 b6 b7 b8 b9:uint64) : Lemma
(requires
v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\
v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\
v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\
v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\
v b4 == nat_from_bytes_le (Seq.slice k 28 35) /\
v b5 == nat_from_bytes_le (Seq.slice k 35 42) /\
v b6 == nat_from_bytes_le (Seq.slice k 42 49) /\
v b7 == nat_from_bytes_le (Seq.slice k 49 56) /\
v b8 == nat_from_bytes_le (Seq.slice k 56 63) /\
v b9 == v (Seq.index k 63)
)
(ensures S56.wide_as_nat5 (b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) == nat_from_bytes_le k)
=
lemma_nat_from_bytes_le_append (Seq.slice k 0 7) (Seq.slice k 7 14);
lemma_nat_from_bytes_le_append (Seq.slice k 0 14) (Seq.slice k 14 21);
lemma_nat_from_bytes_le_append (Seq.slice k 0 21) (Seq.slice k 21 28);
lemma_nat_from_bytes_le_append (Seq.slice k 0 28) (Seq.slice k 28 35);
lemma_nat_from_bytes_le_append (Seq.slice k 0 35) (Seq.slice k 35 42);
lemma_nat_from_bytes_le_append (Seq.slice k 0 42) (Seq.slice k 42 49);
lemma_nat_from_bytes_le_append (Seq.slice k 0 49) (Seq.slice k 49 56);
lemma_nat_from_bytes_le_append (Seq.slice k 0 56) (Seq.slice k 56 63);
lemma_nat_from_bytes_le_append (Seq.slice k 0 63) (Seq.create 1 (Seq.index k 63));
assert (Seq.append (Seq.slice k 0 7) (Seq.slice k 7 14) `Seq.equal` Seq.slice k 0 14);
assert (Seq.append (Seq.slice k 0 14) (Seq.slice k 14 21) `Seq.equal` Seq.slice k 0 21);
assert (Seq.append (Seq.slice k 0 21) (Seq.slice k 21 28) `Seq.equal` Seq.slice k 0 28);
assert (Seq.append (Seq.slice k 0 28) (Seq.slice k 28 35) `Seq.equal` Seq.slice k 0 35);
assert (Seq.append (Seq.slice k 0 35) (Seq.slice k 35 42) `Seq.equal` Seq.slice k 0 42);
assert (Seq.append (Seq.slice k 0 42) (Seq.slice k 42 49) `Seq.equal` Seq.slice k 0 49);
assert (Seq.append (Seq.slice k 0 49) (Seq.slice k 49 56) `Seq.equal` Seq.slice k 0 56);
assert (Seq.append (Seq.slice k 0 56) (Seq.slice k 56 63) `Seq.equal` Seq.slice k 0 63);
assert (Seq.append (Seq.slice k 0 63) (Seq.create 1 (Seq.index k 63)) `Seq.equal` k);
nat_from_intseq_le_lemma0 (Seq.create 1 (Seq.index k 63));
assert_norm (pow2 56 == 0x100000000000000);
assert_norm (pow2 112 == 0x10000000000000000000000000000);
assert_norm (pow2 168 == 0x1000000000000000000000000000000000000000000);
assert_norm (pow2 224 == 0x100000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 280 == 0x10000000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 336 == 0x1000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 392 == 0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 448 == 0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 504 == 0x1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
#pop-options
val load_64_bytes:
out:lbuffer uint64 10ul
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h out /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F56.wide_as_nat h1 out == nat_from_bytes_le (as_seq h0 b) /\
F56.qelem_wide_fits h1 out (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
)
[@CInline]
let load_64_bytes out b =
let h0 = ST.get() in
let b0 = hload56_le b 0ul in
let b1 = hload56_le b 7ul in
let b2 = hload56_le b 14ul in
let b3 = hload56_le b 21ul in
let b4 = hload56_le b 28ul in
let b5 = hload56_le b 35ul in
let b6 = hload56_le b 42ul in
let b7 = hload56_le b 49ul in
let b8 = hload56_le b 56ul in
let b63 = b.(63ul) in
let b9 = to_u64 b63 in
lemma_load_64_bytes (as_seq h0 b) b0 b1 b2 b3 b4 b5 b6 b7 b8 b9;
Hacl.Bignum25519.make_u64_10 out b0 b1 b2 b3 b4 b5 b6 b7 b8 b9
inline_for_extraction noextract
val hload56_le':
b:lbuffer uint8 32ul
-> off:size_t{v off <= 21} ->
Stack uint64
(requires fun h -> live h b)
(ensures fun h0 z h1 -> h0 == h1 /\
v z < 0x100000000000000 /\
v z == nat_from_bytes_le (Seq.slice (as_seq h0 b) (v off) (v off + 7))
)
let hload56_le' b off =
let h0 = ST.get() in
let b8 = sub b off 8ul in
let z = uint_from_bytes_le b8 in
let z' = z &. u64 0xffffffffffffff in
assert_norm (0xffffffffffffff == pow2 56 - 1);
assert_norm (0x100000000000000 == pow2 56 );
calc (==) {
v z' <: nat;
(==) { }
v (z &. u64 0xffffffffffffff);
(==) { logand_spec z (u64 0xffffffffffffff) }
v z `logand_v` 0xffffffffffffff;
(==) { assert_norm(pow2 56 - 1 == 0xffffffffffffff); UInt.logand_mask (UInt.to_uint_t 64 (v z)) 56 }
(v z % pow2 56);
(==) { lemma_reveal_uint_to_bytes_le #U64 #SEC (as_seq h0 b8) }
nat_from_bytes_le (as_seq h0 b8) % pow2 56;
(==) { nat_from_intseq_le_slice_lemma (as_seq h0 b8) 7 }
(nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) +
pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) % pow2 56;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r
(nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7))
(pow2 (7 * 8) * nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8))
(pow2 56);
FStar.Math.Lemmas.swap_mul (pow2 (7 * 8)) (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8));
FStar.Math.Lemmas.cancel_mul_mod (nat_from_bytes_le (Seq.slice (as_seq h0 b8) 7 8)) (pow2 56) }
nat_from_bytes_le (Seq.slice (as_seq h0 b8) 0 7) <: nat;
};
assert (Seq.equal
(Seq.slice (as_seq h0 b) (v off) (v off + 7))
(Seq.slice (as_seq h0 b8) 0 7));
z' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"Hacl.Impl.BignumQ.Mul.fsti.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Load56.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": "S56"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.BignumQ.Mul",
"short_module": "F56"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.ByteSequence.lbytes 32 ->
b0: Lib.IntTypes.uint64 ->
b1: Lib.IntTypes.uint64 ->
b2: Lib.IntTypes.uint64 ->
b3: Lib.IntTypes.uint64 ->
b4: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(requires
Lib.IntTypes.v b0 == Lib.ByteSequence.nat_from_bytes_le (FStar.Seq.Base.slice k 0 7) /\
Lib.IntTypes.v b1 == Lib.ByteSequence.nat_from_bytes_le (FStar.Seq.Base.slice k 7 14) /\
Lib.IntTypes.v b2 == Lib.ByteSequence.nat_from_bytes_le (FStar.Seq.Base.slice k 14 21) /\
Lib.IntTypes.v b3 == Lib.ByteSequence.nat_from_bytes_le (FStar.Seq.Base.slice k 21 28) /\
Lib.IntTypes.v b4 == Lib.ByteSequence.nat_from_bytes_le (FStar.Seq.Base.slice k 28 32))
(ensures
Hacl.Spec.BignumQ.Definitions.as_nat5 (b0, b1, b2, b3, b4) ==
Lib.ByteSequence.nat_from_bytes_le k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.ByteSequence.lbytes",
"Lib.IntTypes.uint64",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.append",
"FStar.Seq.Base.slice",
"Hacl.Impl.Load56.lemma_nat_from_bytes_le_append",
"Prims.l_and",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.Sequence.length",
"Lib.IntTypes.v",
"Lib.ByteSequence.nat_from_bytes_le",
"Prims.squash",
"Prims.nat",
"Hacl.Spec.BignumQ.Definitions.as_nat5",
"FStar.Pervasives.Native.Mktuple5",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_load_32_bytes (k: lbytes 32) (b0 b1 b2 b3 b4: uint64)
: Lemma
(requires
v b0 == nat_from_bytes_le (Seq.slice k 0 7) /\ v b1 == nat_from_bytes_le (Seq.slice k 7 14) /\
v b2 == nat_from_bytes_le (Seq.slice k 14 21) /\
v b3 == nat_from_bytes_le (Seq.slice k 21 28) /\
v b4 == nat_from_bytes_le (Seq.slice k 28 32))
(ensures S56.as_nat5 (b0, b1, b2, b3, b4) == nat_from_bytes_le k) =
| lemma_nat_from_bytes_le_append (Seq.slice k 0 7) (Seq.slice k 7 14);
lemma_nat_from_bytes_le_append (Seq.slice k 0 14) (Seq.slice k 14 21);
lemma_nat_from_bytes_le_append (Seq.slice k 0 21) (Seq.slice k 21 28);
lemma_nat_from_bytes_le_append (Seq.slice k 0 28) (Seq.slice k 28 32);
assert ((Seq.append (Seq.slice k 0 7) (Seq.slice k 7 14)) `Seq.equal` (Seq.slice k 0 14));
assert ((Seq.append (Seq.slice k 0 14) (Seq.slice k 14 21)) `Seq.equal` (Seq.slice k 0 21));
assert ((Seq.append (Seq.slice k 0 21) (Seq.slice k 21 28)) `Seq.equal` (Seq.slice k 0 28));
assert ((Seq.append (Seq.slice k 0 28) (Seq.slice k 28 32)) `Seq.equal` k);
assert_norm (pow2 56 == 0x100000000000000);
assert_norm (pow2 112 == 0x10000000000000000000000000000);
assert_norm (pow2 168 == 0x1000000000000000000000000000000000000000000);
assert_norm (pow2 224 == 0x100000000000000000000000000000000000000000000000000000000) | false |
Vale.X64.Memory.fsti | Vale.X64.Memory.base_typ_as_vale_type | val base_typ_as_vale_type (t: base_typ) : Tot eqtype | val base_typ_as_vale_type (t: base_typ) : Tot eqtype | let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 39,
"start_col": 0,
"start_line": 33
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 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 | t: Vale.Arch.HeapTypes_s.base_typ -> Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.nat8",
"Vale.X64.Memory.nat16",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.nat64",
"Vale.X64.Memory.quad32",
"Prims.eqtype"
] | [] | false | false | false | true | false | let base_typ_as_vale_type (t: base_typ) : Tot eqtype =
| match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32 | false |
Pulse.Reflection.Util.fst | Pulse.Reflection.Util.mk_opaque_let | val mk_opaque_let
(g: R.env)
(nm: string)
(tm: Ghost.erased R.term)
(ty: R.typ{RT.typing g tm (T.E_Total, ty)})
: T.Tac (RT.sigelt_for g) | val mk_opaque_let
(g: R.env)
(nm: string)
(tm: Ghost.erased R.term)
(ty: R.typ{RT.typing g tm (T.E_Total, ty)})
: T.Tac (RT.sigelt_for g) | let mk_opaque_let (g:R.env) (nm:string) (tm:Ghost.erased R.term) (ty:R.typ{RT.typing g tm (T.E_Total, ty)}) : T.Tac (RT.sigelt_for g) =
let fv = R.pack_fv (T.cur_module () @ [nm]) in
let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) }) in
let se = R.pack_sigelt (R.Sg_Let false [lb]) in
let pf : RT.sigelt_typing g se =
RT.ST_Let_Opaque g fv ty ()
in
(true, se, None) | {
"file_name": "lib/steel/pulse/Pulse.Reflection.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 739,
"start_col": 0,
"start_line": 732
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Reflection.Util
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
open FStar.List.Tot
let u_two = RT.(u_succ (u_succ u_zero))
let u_max_two u = (RT.u_max u_two u)
let pulse_lib_core = ["Pulse"; "Lib"; "Core"]
let mk_pulse_lib_core_lid s = pulse_lib_core@[s]
let tun = R.pack_ln R.Tv_Unknown
let unit_lid = R.unit_lid
let bool_lid = R.bool_lid
let int_lid = R.int_lid
let erased_lid = ["FStar"; "Ghost"; "erased"]
let hide_lid = ["FStar"; "Ghost"; "hide"]
let reveal_lid = ["FStar"; "Ghost"; "reveal"]
let vprop_lid = mk_pulse_lib_core_lid "vprop"
let vprop_fv = R.pack_fv vprop_lid
let vprop_tm = R.pack_ln (R.Tv_FVar vprop_fv)
let unit_fv = R.pack_fv unit_lid
let unit_tm = R.pack_ln (R.Tv_FVar unit_fv)
let bool_fv = R.pack_fv bool_lid
let bool_tm = R.pack_ln (R.Tv_FVar bool_fv)
let nat_lid = ["Prims"; "nat"]
let nat_fv = R.pack_fv nat_lid
let nat_tm = R.pack_ln (R.Tv_FVar nat_fv)
let szt_lid = ["FStar"; "SizeT"; "t"]
let szt_fv = R.pack_fv szt_lid
let szt_tm = R.pack_ln (R.Tv_FVar szt_fv)
let szv_lid = ["FStar"; "SizeT"; "v"]
let szv_fv = R.pack_fv szv_lid
let szv_tm = R.pack_ln (R.Tv_FVar szv_fv)
let seq_lid = ["FStar"; "Seq"; "Base"; "seq"]
let seq_create_lid = ["FStar"; "Seq"; "Base"; "create"]
let tot_lid = ["Prims"; "Tot"]
(* The "plicities" *)
let ex t : R.argv = (t, R.Q_Explicit)
let im t : R.argv = (t, R.Q_Implicit)
let tuple2_lid = ["FStar"; "Pervasives"; "Native"; "tuple2"]
let fst_lid = ["FStar"; "Pervasives"; "Native"; "fst"]
let snd_lid = ["FStar"; "Pervasives"; "Native"; "snd"]
let mk_tuple2 (u1 u2:R.universe) (a1 a2:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv tuple2_lid) [u1; u2]) in
let t = pack_ln (Tv_App t (a1, Q_Explicit)) in
pack_ln (Tv_App t (a2, Q_Explicit))
let mk_fst (u1 u2:R.universe) (a1 a2 e:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv fst_lid) [u1; u2]) in
let t = pack_ln (Tv_App t (a1, Q_Implicit)) in
let t = pack_ln (Tv_App t (a2, Q_Implicit)) in
pack_ln (Tv_App t (e, Q_Explicit))
let mk_snd (u1 u2:R.universe) (a1 a2 e:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv snd_lid) [u1; u2]) in
let t = pack_ln (Tv_App t (a1, Q_Implicit)) in
let t = pack_ln (Tv_App t (a2, Q_Implicit)) in
pack_ln (Tv_App t (e, Q_Explicit))
let true_tm = R.pack_ln (R.Tv_Const (R.C_True))
let false_tm = R.pack_ln (R.Tv_Const (R.C_False))
let inv_lid = mk_pulse_lib_core_lid "inv"
let emp_lid = mk_pulse_lib_core_lid "emp"
let inames_lid = mk_pulse_lib_core_lid "inames"
let star_lid = mk_pulse_lib_core_lid "op_Star_Star"
let mk_star (l r:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv star_lid)) in
let t = pack_ln (Tv_App t (l, Q_Explicit)) in
pack_ln (Tv_App t (r, Q_Explicit))
let pure_lid = mk_pulse_lib_core_lid "pure"
let exists_lid = mk_pulse_lib_core_lid "op_exists_Star"
let pulse_lib_forall = ["Pulse"; "Lib"; "Forall"]
let mk_pulse_lib_forall_lid s = pulse_lib_forall@[s]
let forall_lid = mk_pulse_lib_forall_lid "op_forall_Star"
let args_of (tms:list R.term) =
List.Tot.map (fun x -> x, R.Q_Explicit) tms
let mk_pure (p:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv pure_lid)) in
pack_ln (Tv_App t (p, Q_Explicit))
let uzero = R.pack_universe (R.Uv_Zero)
let pulse_lib_reference = ["Pulse"; "Lib"; "Reference"]
let mk_pulse_lib_reference_lid s = pulse_lib_reference@[s]
let mk_squash (u:R.universe) (ty:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv R.squash_qn) [u]) in
pack_ln (Tv_App t (ty, Q_Explicit))
let mk_eq2 (u:R.universe) (ty e1 e2:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv R.eq2_qn) [u]) in
let t = pack_ln (Tv_App t (ty, Q_Implicit)) in
let t = pack_ln (Tv_App t (e1, Q_Explicit)) in
pack_ln (Tv_App t (e2, Q_Explicit))
let stt_admit_lid = mk_pulse_lib_core_lid "stt_admit"
let mk_stt_admit (u:R.universe) (t pre post:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv stt_admit_lid) [u]) in
let t = pack_ln (Tv_App t (t, Q_Explicit)) in
let t = pack_ln (Tv_App t (pre, Q_Explicit)) in
pack_ln (Tv_App t (post, Q_Explicit))
let stt_atomic_admit_lid = mk_pulse_lib_core_lid "stt_atomic_admit"
let mk_stt_atomic_admit (u:R.universe) (t pre post:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv stt_atomic_admit_lid) [u]) in
let t = pack_ln (Tv_App t (t, Q_Explicit)) in
let t = pack_ln (Tv_App t (pre, Q_Explicit)) in
pack_ln (Tv_App t (post, Q_Explicit))
let stt_ghost_admit_lid = mk_pulse_lib_core_lid "stt_ghost_admit"
let mk_stt_ghost_admit (u:R.universe) (t pre post:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv stt_ghost_admit_lid) [u]) in
let t = pack_ln (Tv_App t (t, Q_Explicit)) in
let t = pack_ln (Tv_App t (pre, Q_Explicit)) in
pack_ln (Tv_App t (post, Q_Explicit))
let emp_inames_lid = mk_pulse_lib_core_lid "emp_inames"
let all_inames_lid = mk_pulse_lib_core_lid "all_inames"
let add_inv_lid = mk_pulse_lib_core_lid "add_inv"
let remove_inv_lid = mk_pulse_lib_core_lid "remove_inv"
let elim_pure_lid = mk_pulse_lib_core_lid "elim_pure"
//the thunked, value-type counterpart of the effect STT
let stt_lid = mk_pulse_lib_core_lid "stt"
let stt_fv = R.pack_fv stt_lid
let stt_tm = R.pack_ln (R.Tv_FVar stt_fv)
let mk_stt_comp (u:R.universe) (res pre post:R.term) : Tot R.term =
let t = R.pack_ln (R.Tv_UInst stt_fv [u]) in
let t = R.pack_ln (R.Tv_App t (res, R.Q_Explicit)) in
let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let stt_atomic_lid = mk_pulse_lib_core_lid "stt_atomic"
let stt_atomic_fv = R.pack_fv stt_atomic_lid
let stt_atomic_tm = R.pack_ln (R.Tv_FVar stt_atomic_fv)
let stt_unobservable_lid = mk_pulse_lib_core_lid "stt_unobservable"
let stt_unobservable_fv = R.pack_fv stt_unobservable_lid
let stt_unobservable_tm = R.pack_ln (R.Tv_FVar stt_unobservable_fv)
let mk_stt_atomic_comp (obs:R.term) (u:R.universe) (a inames pre post:R.term) =
let head = stt_atomic_fv in
let t = R.pack_ln (R.Tv_UInst head [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in
let t = R.pack_ln (R.Tv_App t (obs, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (inames, R.Q_Explicit)) in
let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let stt_ghost_lid = mk_pulse_lib_core_lid "stt_ghost"
let stt_ghost_fv = R.pack_fv stt_ghost_lid
let stt_ghost_tm = R.pack_ln (R.Tv_FVar stt_ghost_fv)
let mk_stt_ghost_comp (u:R.universe) (a pre post:R.term) =
let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in
let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let mk_stt_ghost_comp_post_equiv (g:R.env) (u:R.universe) (a pre post1 post2:R.term)
(posts_equiv:RT.equiv g post1 post2)
: RT.equiv g (mk_stt_ghost_comp u a pre post1)
(mk_stt_ghost_comp u a pre post2) =
let open R in
let open RT in
let t = R.pack_ln (R.Tv_UInst stt_ghost_fv [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Explicit)) in
let t = R.pack_ln (R.Tv_App t (pre, R.Q_Explicit)) in
Rel_ctxt g post1 post2
(Ctxt_app_arg t Q_Explicit Ctxt_hole)
posts_equiv
let mk_total t = R.C_Total t
let mk_ghost t = R.C_GTotal t
let binder_of_t_q t q = RT.binder_of_t_q t q
let binder_of_t_q_s (t:R.term) (q:R.aqualv) (s:RT.pp_name_t) = RT.mk_binder s t q
let bound_var i : R.term = RT.bound_var i
let mk_name i : R.term = R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv i)))
let arrow_dom = (R.term & R.aqualv)
let mk_arrow (f:arrow_dom) (out:R.term) : R.term =
let ty, q = f in
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty q) (R.pack_comp (mk_total out)))
let mk_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term =
let ty, q = f in
R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_total out)))
let mk_ghost_arrow_with_name (s:RT.pp_name_t) (f:arrow_dom) (out:R.term) : R.term =
let ty, q = f in
R.pack_ln (R.Tv_Arrow (binder_of_t_q_s ty q s) (R.pack_comp (mk_ghost out)))
let mk_abs ty qual t : R.term = RT.mk_abs ty qual t
let mk_abs_with_name s ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q_s ty qual s) t)
let mk_abs_with_name_and_range s r ty qual t : R.term =
let b = (binder_of_t_q_s ty qual s) in
let b = RU.binder_set_range b r in
R.pack_ln (R.Tv_Abs b t)
let mk_erased (u:R.universe) (t:R.term) : R.term =
let hd = R.pack_ln (R.Tv_UInst (R.pack_fv erased_lid) [u]) in
R.pack_ln (R.Tv_App hd (t, R.Q_Explicit))
let mk_reveal (u:R.universe) (t:R.term) (e:R.term) : R.term =
let hd = R.pack_ln (R.Tv_UInst (R.pack_fv reveal_lid) [u]) in
let hd = R.pack_ln (R.Tv_App hd (t, R.Q_Implicit)) in
R.pack_ln (R.Tv_App hd (e, R.Q_Explicit))
let elim_exists_lid = mk_pulse_lib_core_lid "elim_exists"
let intro_exists_lid = mk_pulse_lib_core_lid "intro_exists"
let intro_exists_erased_lid = mk_pulse_lib_core_lid "intro_exists_erased"
let mk_exists (u:R.universe) (a p:R.term) =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv exists_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in
R.pack_ln (R.Tv_App t (p, R.Q_Explicit))
let mk_forall (u:R.universe) (a p:R.term) =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv forall_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in
R.pack_ln (R.Tv_App t (p, R.Q_Explicit))
let mk_elim_exists (u:R.universe) (a p:R.term) : R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv elim_exists_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in
R.pack_ln (R.Tv_App t (p, R.Q_Explicit))
let mk_intro_exists (u:R.universe) (a p:R.term) (e:R.term) : R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (e, R.Q_Explicit))
let mk_intro_exists_erased (u:R.universe) (a p:R.term) (e:R.term) : R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv intro_exists_erased_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (a, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (p, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (e, R.Q_Explicit))
let while_lid = ["Pulse"; "Lib"; "WhileLoop"; "while_loop"]
let mk_while (inv cond body:R.term) : R.term =
let t = R.pack_ln (R.Tv_FVar (R.pack_fv while_lid)) in
let t = R.pack_ln (R.Tv_App t (inv, R.Q_Explicit)) in
let t = R.pack_ln (R.Tv_App t (cond, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (body, R.Q_Explicit))
let vprop_eq_tm t1 t2 =
let open R in
let u2 =
pack_universe (Uv_Succ (pack_universe (Uv_Succ (pack_universe Uv_Zero)))) in
let t = pack_ln (Tv_UInst (pack_fv eq2_qn) [u2]) in
let t = pack_ln (Tv_App t (pack_ln (Tv_FVar (pack_fv vprop_lid)), Q_Implicit)) in
let t = pack_ln (Tv_App t (t1, Q_Explicit)) in
let t = pack_ln (Tv_App t (t2, Q_Explicit)) in
t
let emp_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv emp_inames_lid))
let all_inames_tm : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv all_inames_lid))
let add_inv_tm (p is i : R.term) : R.term =
let h = R.pack_ln (R.Tv_FVar (R.pack_fv add_inv_lid)) in
R.mk_app h [im p; ex is; ex i]
let remove_inv_tm (p is i : R.term) : R.term =
let h = R.pack_ln (R.Tv_FVar (R.pack_fv remove_inv_lid)) in
R.mk_app h [im p; ex is; ex i]
let non_informative_witness_lid = mk_pulse_lib_core_lid "non_informative_witness"
let non_informative_witness_rt (u:R.universe) (a:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (pack_fv non_informative_witness_lid) [u]) in
let t = pack_ln (Tv_App t (a, Q_Explicit)) in
t
let stt_vprop_equiv_fv =
R.pack_fv (mk_pulse_lib_core_lid "vprop_equiv")
let stt_vprop_equiv_tm =
R.pack_ln (R.Tv_FVar stt_vprop_equiv_fv)
let stt_vprop_equiv (t1 t2:R.term) =
let open R in
let t = pack_ln (Tv_App stt_vprop_equiv_tm (t1, Q_Explicit)) in
pack_ln (Tv_App t (t2, Q_Explicit))
let return_stt_lid = mk_pulse_lib_core_lid "return_stt"
let return_stt_noeq_lid = mk_pulse_lib_core_lid "return"
let return_stt_atomic_lid = mk_pulse_lib_core_lid "return_stt_atomic"
let return_stt_atomic_noeq_lid = mk_pulse_lib_core_lid "return_stt_atomic_noeq"
let return_stt_ghost_lid = mk_pulse_lib_core_lid "return_stt_ghost"
let return_stt_ghost_noeq_lid = mk_pulse_lib_core_lid "return_stt_ghost_noeq"
let mk_stt_return (u:R.universe) (ty:R.term) (t:R.term) (post:R.term)
: R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv return_stt_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (ty, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (t, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let mk_stt_return_noeq (u:R.universe) (ty:R.term) (t:R.term) (post:R.term)
: R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv return_stt_noeq_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (ty, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (t, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let mk_stt_atomic_return (u:R.universe) (ty:R.term) (t:R.term) (post:R.term)
: R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv return_stt_atomic_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (ty, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (t, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let mk_stt_atomic_return_noeq (u:R.universe) (ty:R.term) (t:R.term) (post:R.term)
: R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv return_stt_atomic_noeq_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (ty, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (t, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let mk_stt_ghost_return (u:R.universe) (ty:R.term) (t:R.term) (post:R.term)
: R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv return_stt_ghost_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (ty, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (t, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
let mk_stt_ghost_return_noeq (u:R.universe) (ty:R.term) (t:R.term) (post:R.term)
: R.term =
let t = R.pack_ln (R.Tv_UInst (R.pack_fv return_stt_ghost_noeq_lid) [u]) in
let t = R.pack_ln (R.Tv_App t (ty, R.Q_Implicit)) in
let t = R.pack_ln (R.Tv_App t (t, R.Q_Explicit)) in
R.pack_ln (R.Tv_App t (post, R.Q_Explicit))
// Wrapper.lift_stt_atomic<u> #a #pre #post e
let mk_lift_atomic_stt (u:R.universe) (a pre post e:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "lift_stt_atomic" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post, Q_Implicit)) in
pack_ln (R.Tv_App t (e, Q_Explicit))
let mk_lift_ghost_neutral (u:R.universe) (a pre post e reveal_a:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "lift_ghost_neutral" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (e, Q_Explicit)) in
pack_ln (R.Tv_App t (reveal_a, Q_Explicit))
let mk_lift_neutral_ghost (u:R.universe) (a pre post e:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "lift_neutral_ghost" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (e, Q_Explicit)) in
t
let mk_lift_observability (u:R.universe) (a o1 o2 opened pre post e : R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "lift_observablility" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (o1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (o2, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (opened, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post, Q_Implicit)) in
pack_ln (R.Tv_App t (e, Q_Explicit))
// Wrapper.bind_stt<u1, u2> #a #b #pre1 #post1 #post2 e1 e2
let mk_bind_stt
(u1 u2:R.universe)
(ty1 ty2:R.term)
(pre1 post1: R.term)
(post2: R.term)
(t1 t2:R.term)
: R.term
= let bind_lid = mk_pulse_lib_core_lid "bind_stt" in
let head = R.pack_ln (R.Tv_UInst (R.pack_fv bind_lid) [u1;u2]) in
R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app head
[(ty1, R.Q_Implicit)])
[(ty2, R.Q_Implicit)])
[(pre1, R.Q_Implicit)])
[(post1, R.Q_Implicit)])
[(post2, R.Q_Implicit)])
[(t1, R.Q_Explicit)])
[(t2, R.Q_Explicit)]
let mk_bind_ghost
(u1 u2:R.universe)
(a b pre1 post1 post2 e1 e2:R.term) =
let open R in
let bind_lid = mk_pulse_lib_core_lid "bind_ghost" in
let t = R.pack_ln (R.Tv_UInst (R.pack_fv bind_lid) [u1;u2]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (b, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post2, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (e1, Q_Explicit)) in
pack_ln (R.Tv_App t (e2, Q_Explicit))
let mk_bind_atomic
(u1 u2:R.universe)
(a b obs1 obs2 opens pre1 post1 post2 e1 e2:R.term) =
let open R in
let bind_lid = mk_pulse_lib_core_lid "bind_atomic" in
let t = R.pack_ln (R.Tv_UInst (R.pack_fv bind_lid) [u1;u2]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (b, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (obs1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (obs2, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (opens, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post2, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (e1, Q_Explicit)) in
pack_ln (R.Tv_App t (e2, Q_Explicit))
// Wrapper.frame_stt<u> #ty #pre #post frame t
let mk_frame_stt
(u:R.universe)
(ty:R.term)
(pre: R.term)
(post: R.term)
(frame: R.term)
(t:R.term)
: R.term
= let frame_lid = mk_pulse_lib_core_lid "frame_stt" in
let frame_fv = R.pack_fv frame_lid in
let frame_univ_inst u = R.pack_ln (R.Tv_UInst (R.pack_fv frame_lid) [u]) in
let head = frame_univ_inst u in
R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app head [(ty, R.Q_Implicit)])
[(pre, R.Q_Implicit)])
[(post, R.Q_Implicit)])
[(frame, R.Q_Explicit)])
[(t, R.Q_Explicit)]
// Wrapper.frame_stt_atomic<u> #a #opened #pre #post frame e
let mk_frame_stt_atomic (u:R.universe) (a opened pre post frame e:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "frame_atomic" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (opened, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (frame, Q_Explicit)) in
pack_ln (R.Tv_App t (e, Q_Explicit))
// Wrapper.frame_stt_ghost<u> #a #opened #pre #post frame e
let mk_frame_stt_ghost (u:R.universe) (a pre post frame e:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "frame_ghost" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (frame, Q_Explicit)) in
pack_ln (R.Tv_App t (e, Q_Explicit))
// Wrapper.sub_stt<u> #ty #pre1 pre2 #post1 post2 () () e
let mk_sub_stt
(u:R.universe)
(ty:R.term)
(pre1 pre2: R.term)
(post1 post2: R.term)
(t:R.term)
: R.term
= let subsumption_lid = mk_pulse_lib_core_lid "sub_stt" in
let subsumption_fv = R.pack_fv subsumption_lid in
let subsumption_univ_inst u = R.pack_ln (R.Tv_UInst subsumption_fv [u]) in
let head = subsumption_univ_inst u in
R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app
(R.mk_app head [(ty, R.Q_Implicit)])
[(pre1, R.Q_Implicit)])
[(pre2, R.Q_Explicit)])
[(post1, R.Q_Implicit)])
[(post2, R.Q_Explicit)])
[(`(), R.Q_Explicit)])
[(`(), R.Q_Explicit)])
[(t, R.Q_Explicit)]
// Wrapper.sub_stt_atomic<u> #a #opened #pre1 pre2 #post1 post2 () () e
let mk_sub_stt_atomic (u:R.universe) (a opened pre1 pre2 post1 post2 e:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "sub_atomic" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (opened, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre2, Q_Explicit)) in
let t = pack_ln (R.Tv_App t (post1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post2, Q_Explicit)) in
let t = pack_ln (R.Tv_App t (`(), Q_Explicit)) in
let t = pack_ln (R.Tv_App t (`(), Q_Explicit)) in
pack_ln (R.Tv_App t (e, Q_Explicit))
let mk_sub_inv_atomic (u:R.universe) (a pre post opens1 opens2 e : R.term) : R.term =
let open R in
let lid = mk_pulse_lib_core_lid "sub_invs_atomic" in
let head : R.term = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
R.mk_app head
[(a, Q_Implicit);
(opens1, Q_Implicit);
(opens2, Q_Implicit);
(pre, Q_Implicit);
(post, Q_Implicit);
(e, Q_Explicit)]
// Wrapper.sub_stt_ghost<u> #a #opened #pre1 pre2 #post1 post2 () () e
let mk_sub_stt_ghost (u:R.universe) (a pre1 pre2 post1 post2 e:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "sub_ghost" in
let t = pack_ln (R.Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (R.Tv_App t (a, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (pre2, Q_Explicit)) in
let t = pack_ln (R.Tv_App t (post1, Q_Implicit)) in
let t = pack_ln (R.Tv_App t (post2, Q_Explicit)) in
let t = pack_ln (R.Tv_App t (`(), Q_Explicit)) in
let t = pack_ln (R.Tv_App t (`(), Q_Explicit)) in
pack_ln (R.Tv_App t (e, Q_Explicit))
let mk_par (u:R.universe) (aL aR preL postL preR postR eL eR:R.term) =
let open R in
let lid = mk_pulse_lib_core_lid "par_stt" in
let t = pack_ln (Tv_UInst (R.pack_fv lid) [u]) in
let t = pack_ln (Tv_App t (aL, Q_Implicit)) in
let t = pack_ln (Tv_App t (aR, Q_Implicit)) in
let t = pack_ln (Tv_App t (preL, Q_Implicit)) in
let t = pack_ln (Tv_App t (postL, Q_Implicit)) in
let t = pack_ln (Tv_App t (preR, Q_Implicit)) in
let t = pack_ln (Tv_App t (postR, Q_Implicit)) in
let t = pack_ln (Tv_App t (eL, Q_Explicit)) in
pack_ln (Tv_App t (eR, Q_Explicit))
let mk_rewrite (p q:R.term) =
let open R in
let t = pack_ln (Tv_FVar (pack_fv (mk_pulse_lib_core_lid "rewrite"))) in
let t = pack_ln (Tv_App t (p, Q_Explicit)) in
let t = pack_ln (Tv_App t (q, Q_Explicit)) in
pack_ln (Tv_App t (`(), Q_Explicit))
let mk_withlocal (ret_u:R.universe) (a init pre ret_t post body:R.term) =
let open R in
let lid = mk_pulse_lib_reference_lid "with_local" in
let t = pack_ln (Tv_UInst (R.pack_fv lid) [ret_u]) in
let t = pack_ln (Tv_App t (a, Q_Implicit)) in
let t = pack_ln (Tv_App t (init, Q_Explicit)) in
let t = pack_ln (Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (Tv_App t (ret_t, Q_Implicit)) in
let t = pack_ln (Tv_App t (post, Q_Implicit)) in
pack_ln (Tv_App t (body, Q_Explicit))
///// Utils to derive equiv for common constructs /////
let mk_star_equiv (g:R.env) (t1 t2 t3 t4:R.term)
(eq1:RT.equiv g t1 t3)
(eq2:RT.equiv g t2 t4)
: RT.equiv g (mk_star t1 t2) (mk_star t3 t4) =
admit ()
let mk_stt_comp_equiv (g:R.env) (u:R.universe) (res1 pre1 post1 res2 pre2 post2:R.term)
(res_eq: RT.equiv g res1 res2)
(pre_eq:RT.equiv g pre1 pre2)
(post_eq:RT.equiv g post1 post2)
: RT.equiv g (mk_stt_comp u res1 pre1 post1)
(mk_stt_comp u res2 pre2 post2)
= admit ()
let mk_stt_atomic_comp_equiv (g:R.env) obs (u:R.universe) (res inames pre1 post1 pre2 post2:R.term)
(pre_eq:RT.equiv g pre1 pre2)
(post_eq:RT.equiv g post1 post2)
: RT.equiv g (mk_stt_atomic_comp obs u res inames pre1 post1)
(mk_stt_atomic_comp obs u res inames pre2 post2)
= admit ()
let mk_stt_ghost_comp_equiv (g:R.env) (u:R.universe) (res pre1 post1 pre2 post2:R.term)
(pre_eq:RT.equiv g pre1 pre2)
(post_eq:RT.equiv g post1 post2)
: RT.equiv g (mk_stt_ghost_comp u res pre1 post1)
(mk_stt_ghost_comp u res pre2 post2)
= admit ()
let ref_lid = mk_pulse_lib_reference_lid "ref"
let pts_to_lid = mk_pulse_lib_reference_lid "pts_to"
let full_perm_lid = ["PulseCore"; "FractionalPermission"; "full_perm"]
let mk_ref (a:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv ref_lid)) in
pack_ln (Tv_App t (a, Q_Explicit))
let mk_pts_to (a:R.term) (r:R.term) (perm:R.term) (v:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv pts_to_lid)) in
let t = pack_ln (Tv_App t (a, Q_Implicit)) in
let t = pack_ln (Tv_App t (r, Q_Explicit)) in
let t = pack_ln (Tv_App t (perm, Q_Implicit)) in
pack_ln (Tv_App t (v, Q_Explicit))
let full_perm_tm : R.term =
let open R in
pack_ln (Tv_FVar (pack_fv full_perm_lid))
let pulse_lib_array_core = ["Pulse"; "Lib"; "Array"; "Core"]
let mk_pulse_lib_array_core_lid s = pulse_lib_array_core @ [s]
let array_lid = mk_pulse_lib_array_core_lid "array"
let array_pts_to_lid = mk_pulse_lib_array_core_lid "pts_to"
let array_length_lid = mk_pulse_lib_array_core_lid "length"
let array_is_full_lid = mk_pulse_lib_array_core_lid "is_full_array"
let mk_array (a:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv array_lid)) in
pack_ln (Tv_App t (a, Q_Explicit))
let mk_array_length (a:R.term) (arr:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv array_length_lid)) in
let t = pack_ln (Tv_App t (a, Q_Implicit)) in
pack_ln (Tv_App t (arr, Q_Explicit))
let mk_array_pts_to (a:R.term) (arr:R.term) (perm:R.term) (v:R.term) : R.term =
let open R in
let t = pack_ln (Tv_FVar (pack_fv array_pts_to_lid)) in
let t = pack_ln (Tv_App t (a, Q_Implicit)) in
let t = pack_ln (Tv_App t (arr, Q_Explicit)) in
let t = pack_ln (Tv_App t (perm, Q_Implicit)) in
pack_ln (Tv_App t (v, Q_Explicit))
// let mk_array_is_full (a:R.term) (arr:R.term) : R.term =
// let open R in
// let t = pack_ln (Tv_FVar (pack_fv array_is_full_lid)) in
// let t = pack_ln (Tv_App t (a, Q_Implicit)) in
// pack_ln (Tv_App t (arr, Q_Explicit))
let mk_seq (u:R.universe) (a:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (R.pack_fv seq_lid) [u]) in
pack_ln (Tv_App t (a, Q_Explicit))
let mk_seq_create (u:R.universe) (a:R.term) (len:R.term) (v:R.term) : R.term =
let open R in
let t = pack_ln (Tv_UInst (R.pack_fv seq_create_lid) [u]) in
let t = pack_ln (Tv_App t (a, Q_Implicit)) in
let t = pack_ln (Tv_App t (len, Q_Explicit)) in
pack_ln (Tv_App t (v, Q_Explicit))
let mk_withlocalarray (ret_u:R.universe) (a init len pre ret_t post body:R.term) =
let open R in
let lid = mk_pulse_lib_array_core_lid "with_local" in
let t = pack_ln (Tv_UInst (R.pack_fv lid) [ret_u]) in
let t = pack_ln (Tv_App t (a, Q_Implicit)) in
let t = pack_ln (Tv_App t (init, Q_Explicit)) in
let t = pack_ln (Tv_App t (len, Q_Explicit)) in
let t = pack_ln (Tv_App t (pre, Q_Implicit)) in
let t = pack_ln (Tv_App t (ret_t, Q_Implicit)) in
let t = pack_ln (Tv_App t (post, Q_Implicit)) in
pack_ln (Tv_App t (body, Q_Explicit))
let mk_szv (n:R.term) =
let open R in
let t = pack_ln (Tv_FVar (pack_fv szv_lid)) in
pack_ln (Tv_App t (n, Q_Explicit)) | {
"checked_file": "/",
"dependencies": [
"Pulse.RuntimeUtils.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Reflection.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
g: FStar.Stubs.Reflection.Types.env ->
nm: Prims.string ->
tm: FStar.Ghost.erased FStar.Stubs.Reflection.Types.term ->
ty:
FStar.Stubs.Reflection.Types.typ
{ FStar.Reflection.Typing.typing g
(FStar.Ghost.reveal tm)
(FStar.Stubs.TypeChecker.Core.E_Total,
ty) }
-> FStar.Tactics.Effect.Tac (FStar.Reflection.Typing.sigelt_for g) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.env",
"Prims.string",
"FStar.Ghost.erased",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Reflection.Typing.typing",
"FStar.Ghost.reveal",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.TypeChecker.Core.E_Total",
"FStar.Pervasives.Native.Mktuple3",
"Prims.bool",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Typing.blob",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Typing.sigelt_typing",
"FStar.Reflection.Typing.ST_Let_Opaque",
"FStar.Stubs.Reflection.V2.Builtins.pack_sigelt",
"FStar.Stubs.Reflection.V2.Data.Sg_Let",
"Prims.Cons",
"FStar.Stubs.Reflection.Types.letbinding",
"Prims.Nil",
"FStar.Stubs.Reflection.V2.Builtins.pack_lb",
"FStar.Stubs.Reflection.V2.Data.Mklb_view",
"FStar.Stubs.Reflection.Types.univ_name",
"FStar.Reflection.Typing.sigelt_for",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Stubs.Reflection.Types.name",
"FStar.List.Tot.Base.op_At",
"Prims.list",
"FStar.Tactics.V2.Derived.cur_module"
] | [] | false | true | false | false | false | let mk_opaque_let
(g: R.env)
(nm: string)
(tm: Ghost.erased R.term)
(ty: R.typ{RT.typing g tm (T.E_Total, ty)})
: T.Tac (RT.sigelt_for g) =
| let fv = R.pack_fv (T.cur_module () @ [nm]) in
let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) }) in
let se = R.pack_sigelt (R.Sg_Let false [lb]) in
let pf:RT.sigelt_typing g se = RT.ST_Let_Opaque g fv ty () in
(true, se, None) | false |
Vale.X64.Memory.fsti | Vale.X64.Memory.init_heaplets_req | val init_heaplets_req : h: Vale.X64.Memory.vale_heap -> bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info
-> Prims.logical | let init_heaplets_req (h:vale_heap) (bs:Seq.seq buffer_info) =
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 106,
"end_line": 381,
"start_col": 0,
"start_line": 377
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
let valid_taint_buf128 (b:buffer128) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
val lemma_valid_taint64
(b:buffer64)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf64 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale8 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 8 ==> Map.sel memTaint i' == t))
val lemma_valid_taint128
(b:buffer128)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf128 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale16 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 16 ==> Map.sel memTaint i' == t))
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_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 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_same_heaplet_id (l:loc) (h1 h2:vale_heap) : Lemma
(requires modifies l h1 h2)
(ensures get_heaplet_id h1 == get_heaplet_id h2)
[SMTPat (modifies l h1 h2); SMTPat (get_heaplet_id h2)]
// Buffers in different heaplets are disjoint
let buffer_info_disjoint (bi1 bi2:buffer_info) =
bi1.bi_typ =!= bi2.bi_typ \/ bi1.bi_heaplet =!= bi2.bi_heaplet ==>
loc_disjoint (loc_buffer bi1.bi_buffer) (loc_buffer bi2.bi_buffer) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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 | h: Vale.X64.Memory.vale_heap -> bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.vale_heap",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.l_and",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.X64.Memory.buffer_readable",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"FStar.Seq.Base.index",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"Vale.X64.Memory.buffer_info_disjoint",
"Prims.logical"
] | [] | false | false | false | true | true | let init_heaplets_req (h: vale_heap) (bs: Seq.seq buffer_info) =
| (forall (i: nat). {:pattern (Seq.index bs i)}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1: nat) (i2: nat). {:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==>
buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) | false |
|
Vale.X64.Memory.fsti | Vale.X64.Memory.loc_mutable_buffers | val loc_mutable_buffers (buffers: list buffer_info) : GTot loc | val loc_mutable_buffers (buffers: list buffer_info) : GTot loc | let rec loc_mutable_buffers (buffers:list buffer_info) : GTot loc =
match buffers with
| [] -> loc_none
| [{bi_mutable = Mutable; bi_buffer = b}] -> loc_buffer b
| ({bi_mutable = Immutable})::t -> loc_mutable_buffers t
| ({bi_mutable = Mutable; bi_buffer = b})::t -> loc_union (loc_buffer b) (loc_mutable_buffers t) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 389,
"start_col": 0,
"start_line": 384
} | module Vale.X64.Memory
include Vale.Arch.HeapTypes_s
open FStar.Mul
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
unfold let vale_heap = vale_heap
unfold let vale_full_heap = vale_full_heap
unfold let heaplet_id = heaplet_id
[@va_qattr]
let get_vale_heap (vhi:vale_full_heap) : vale_heap = vhi.vf_heap
[@va_qattr]
let set_vale_heap (vfh:vale_full_heap) (vh:vale_heap) : vale_full_heap =
{vfh with vf_heap = vh}
let vale_full_heap_equal (h1 h2:vale_full_heap) =
h1.vf_layout == h2.vf_layout /\
h1.vf_heap == h2.vf_heap /\
Map16.equal h1.vf_heaplets h2.vf_heaplets
val get_heaplet_id (h:vale_heap) : option heaplet_id
unfold let nat8 = Vale.Def.Words_s.nat8
unfold let nat16 = Vale.Def.Words_s.nat16
unfold let nat32 = Vale.Def.Words_s.nat32
unfold let nat64 = Vale.Def.Words_s.nat64
unfold let quad32 = Vale.Def.Types_s.quad32
let base_typ_as_vale_type (t:base_typ) : Tot eqtype =
match t with
| TUInt8 -> nat8
| TUInt16 -> nat16
| TUInt32 -> nat32
| TUInt64 -> nat64
| TUInt128 -> quad32
let scale_by (scale index:int) : int = scale * index
unfold let scale2 (index:int) : int = scale_by 2 index
unfold let scale4 (index:int) : int = scale_by 4 index
unfold let scale8 (index:int) : int = scale_by 8 index
unfold let scale16 (index:int) : int = scale_by 16 index
unfold let buffer (t:base_typ) : Type0 = Vale.Arch.HeapImpl.buffer t
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
val buffer_readable (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot prop0
val buffer_writeable (#t:base_typ) (b:buffer t) : GTot prop0
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
val loc : Type u#0
val loc_none : loc
val loc_union (s1 s2:loc) : GTot loc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
val loc_disjoint (s1 s2:loc) : GTot prop0
val loc_includes (s1 s2:loc) : GTot prop0
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
let valid_buffer_read (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
0 <= i /\ i < buffer_length b /\ buffer_readable h b
let valid_buffer_write (#t:base_typ) (h:vale_heap) (b:buffer t) (i:int) : prop0 =
valid_buffer_read h b i /\ buffer_writeable b
// Named abbreviations for Vale type system:
unfold let vuint8 = TUInt8
unfold let vuint16 = TUInt16
unfold let vuint32 = TUInt32
unfold let vuint64 = TUInt64
unfold let vuint128 = TUInt128
let buffer8 = buffer vuint8
let buffer16 = buffer vuint16
let buffer32 = buffer vuint32
let buffer64 = buffer vuint64
let buffer128 = buffer vuint128
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
unfold
let locs_disjoint (ls:list loc) : prop0 =
BigOps.normal (BigOps.pairwise_and' (fun x y -> loc_disjoint x y /\ loc_disjoint y x) ls)
// equivalent to modifies; used to prove modifies clauses via modifies_goal_directed_trans
val modifies_goal_directed (s:loc) (h1 h2:vale_heap) : GTot prop0
val lemma_modifies_goal_directed (s:loc) (h1 h2:vale_heap) : Lemma
(modifies s h1 h2 == modifies_goal_directed s h1 h2)
val buffer_length_buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : Lemma
(requires True)
(ensures (Seq.length (buffer_as_seq h b) == buffer_length b))
[SMTPat (Seq.length (buffer_as_seq h b))]
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma
(requires
loc_disjoint (loc_buffer b) p /\
buffer_readable h b /\
modifies p h h'
)
(ensures
buffer_readable h b /\
buffer_readable h' b /\
buffer_as_seq h b == buffer_as_seq h' b
)
[SMTPatOr [
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)];
[SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)];
]]
val modifies_buffer_addr (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h'
)
(ensures buffer_addr b h == buffer_addr b h')
[SMTPat (modifies p h h'); SMTPat (buffer_addr b h')]
val modifies_buffer_readable (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) : Lemma
(requires
modifies p h h' /\
buffer_readable h b
)
(ensures buffer_readable h' b)
[SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]
val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)]
val loc_disjoint_union_r (s s1 s2:loc) : Lemma
(requires (loc_disjoint s s1 /\ loc_disjoint s s2))
(ensures (loc_disjoint s (loc_union s1 s2)))
[SMTPat (loc_disjoint s (loc_union s1 s2))]
val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)]
val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 s3))
val loc_includes_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_l (s1 s2 s:loc) : Lemma
(requires (loc_includes s1 s \/ loc_includes s2 s))
(ensures (loc_includes (loc_union s1 s2) s))
// for efficiency, no SMT pattern
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_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)]
val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies 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)]
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'))
// for efficiency, no SMT pattern
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))
// for efficiency, no SMT pattern
// Prove (modifies s13 h1 h3).
// To avoid unnecessary matches, don't introduce any other modifies terms.
// Introduce modifies_goal_directed instead.
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_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 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_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 valid_mem64 (ptr:int) (h:vale_heap) : GTot bool // is there a 64-bit word at address ptr?
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool // can we write a 64-bit word at address ptr?
val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 // the 64-bit word at ptr (if valid_mem64 holds)
val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32
val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap
val lemma_valid_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_writeable_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem64 (buffer_addr b h + scale8 i) h
)
val lemma_load_mem64 (b:buffer64) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem64 (buffer_addr b h + scale8 i) h == buffer_read b i 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
)
val lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
valid_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_writeable_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures
writeable_mem128 (buffer_addr b h + scale16 i) h
)
val lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
load_mem128 (buffer_addr b h + scale16 i) h == buffer_read b i 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
)
//Memtaint related functions
type memtaint = memTaint_t
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
let valid_taint_buf64 (b:buffer64) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
let valid_taint_buf128 (b:buffer128) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 =
valid_taint_buf b h mt tn
val lemma_valid_taint64
(b:buffer64)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf64 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale8 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 8 ==> Map.sel memTaint i' == t))
val lemma_valid_taint128
(b:buffer128)
(memTaint:memtaint)
(vale_heap:vale_heap)
(i:nat{i < buffer_length b})
(t:taint)
: Lemma
(requires valid_taint_buf128 b vale_heap memTaint t /\ buffer_readable vale_heap b)
(ensures (
let ptr = buffer_addr b vale_heap + scale16 i in
forall i'.{:pattern Map.sel memTaint i'} i' >= ptr /\ i' < ptr + 16 ==> Map.sel memTaint i' == t))
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_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 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_same_heaplet_id (l:loc) (h1 h2:vale_heap) : Lemma
(requires modifies l h1 h2)
(ensures get_heaplet_id h1 == get_heaplet_id h2)
[SMTPat (modifies l h1 h2); SMTPat (get_heaplet_id h2)]
// Buffers in different heaplets are disjoint
let buffer_info_disjoint (bi1 bi2:buffer_info) =
bi1.bi_typ =!= bi2.bi_typ \/ bi1.bi_heaplet =!= bi2.bi_heaplet ==>
loc_disjoint (loc_buffer bi1.bi_buffer) (loc_buffer bi2.bi_buffer)
// Requirements for enabling heaplets
let init_heaplets_req (h:vale_heap) (bs:Seq.seq buffer_info) =
(forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==>
buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": false,
"full_module": "LowStar.ModifiesPat",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Types",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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 | buffers: Prims.list Vale.Arch.HeapImpl.buffer_info -> Prims.GTot Vale.X64.Memory.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.list",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.X64.Memory.loc_none",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Memory.loc_buffer",
"Vale.X64.Memory.loc_mutable_buffers",
"Vale.X64.Memory.loc_union",
"Vale.X64.Memory.loc"
] | [
"recursion"
] | false | false | false | false | false | let rec loc_mutable_buffers (buffers: list buffer_info) : GTot loc =
| match buffers with
| [] -> loc_none
| [{ bi_mutable = Mutable ; bi_buffer = b }] -> loc_buffer b
| { bi_mutable = Immutable } :: t -> loc_mutable_buffers t
| { bi_mutable = Mutable ; bi_buffer = b } :: t -> loc_union (loc_buffer b) (loc_mutable_buffers t) | false |
MerkleTree.Low.fst | MerkleTree.Low.hash_vv_insert_copy | val hash_vv_insert_copy:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (V.frameOf hs) (B.frameOf v) /\
mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 v /\
V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\
V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\
mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\
RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) ==
RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.hashess_insert
(U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\
S.equal (S.index (RV.as_seq h1 hs) (U32.v lv))
(S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv))
(Rgl?.r_repr (hreg hsz) h0 v)))) | val hash_vv_insert_copy:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (V.frameOf hs) (B.frameOf v) /\
mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 v /\
V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\
V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\
mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\
RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) ==
RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.hashess_insert
(U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\
S.equal (S.index (RV.as_seq h1 hs) (U32.v lv))
(S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv))
(Rgl?.r_repr (hreg hsz) h0 v)))) | let hash_vv_insert_copy #hsz lv i j hs v =
let hh0 = HST.get () in
mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j;
/// 1) Insert an element at the level `lv`, where the new vector is not yet
/// connected to `hs`.
let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in
let hh1 = HST.get () in
// 1-0) Basic disjointness conditions
V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
// 1-1) For the `modifies` postcondition.
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
// 1-2) Preservation
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-3) For `mt_safe_elts`
assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet
// 1-4) For the `rv_inv` postcondition
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v lv);
RV.rv_elems_inv_preserved
hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs))
(U32.v lv + 1) (U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
(U32.v lv + 1) (U32.v (V.size_of hs));
RV.rv_elems_inv_preserved
hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
// assert (rv_itself_inv hh1 hs);
// assert (elems_reg hh1 hs);
// 1-5) Correctness
assert (S.equal (RV.as_seq hh1 ihv)
(S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v)));
/// 2) Assign the updated vector to `hs` at the level `lv`.
RV.assign hs lv ihv;
let hh2 = HST.get () in
// 2-1) For the `modifies` postcondition.
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2);
// 2-2) Preservation
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-3) For `mt_safe_elts`
assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i));
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-4) Correctness
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append
(RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 ihv)
(RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) | {
"file_name": "src/MerkleTree.Low.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 46,
"end_line": 563,
"start_col": 0,
"start_line": 466
} | module MerkleTree.Low
open EverCrypt.Helpers
open FStar.All
open FStar.Integers
open FStar.Mul
open LowStar.Buffer
open LowStar.BufferOps
open LowStar.Vector
open LowStar.Regional
open LowStar.RVector
open LowStar.Regional.Instances
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MHS = FStar.Monotonic.HyperStack
module HH = FStar.Monotonic.HyperHeap
module B = LowStar.Buffer
module CB = LowStar.ConstBuffer
module V = LowStar.Vector
module RV = LowStar.RVector
module RVI = LowStar.Regional.Instances
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module MTH = MerkleTree.New.High
module MTS = MerkleTree.Spec
open Lib.IntTypes
open MerkleTree.Low.Datastructures
open MerkleTree.Low.Hashfunctions
open MerkleTree.Low.VectorExtras
#set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE}
/// Low-level Merkle tree data structure
///
// NOTE: because of a lack of 64-bit LowStar.Buffer support, currently
// we cannot change below to some other types.
type index_t = uint32_t
let uint32_32_max = 4294967295ul
inline_for_extraction
let uint32_max = 4294967295UL
let uint64_max = 18446744073709551615UL
let offset_range_limit = uint32_max
type offset_t = uint64_t
inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64
inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32
private inline_for_extraction
let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit
private inline_for_extraction
let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t =
[@inline_let] let diff = U64.sub_mod index tree in
assert (diff <= offset_range_limit);
Int.Cast.uint64_to_uint32 diff
private inline_for_extraction
let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i)
private inline_for_extraction
let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) =
U64.add tree (u32_64 i)
inline_for_extraction val merkle_tree_size_lg: uint32_t
let merkle_tree_size_lg = 32ul
// A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate
// a Merkle path for each element from the index `i` to `j-1`.
// - Parameters
// `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values.
// `rhs_ok`: to check the rightmost hashes are up-to-date
// `rhs`: a store for "rightmost" hashes, manipulated only when required to
// calculate some merkle paths that need the rightmost hashes
// as a part of them.
// `mroot`: during the construction of `rhs` we can also calculate the Merkle
// root of the tree. If `rhs_ok` is true then it has the up-to-date
// root value.
noeq type merkle_tree =
| MT: hash_size:hash_size_t ->
offset:offset_t ->
i:index_t -> j:index_t{i <= j /\ add64_fits offset j} ->
hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} ->
rhs_ok:bool ->
rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} ->
mroot:hash #hash_size ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) ->
hash_fun:hash_fun_t #hash_size #hash_spec ->
merkle_tree
type mt_p = B.pointer merkle_tree
type const_mt_p = const_pointer merkle_tree
inline_for_extraction
let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool =
j >= i && add64_fits offset j &&
V.size_of hs = merkle_tree_size_lg &&
V.size_of rhs = merkle_tree_size_lg
// The maximum number of currently held elements in the tree is (2^32 - 1).
// cwinter: even when using 64-bit indices, we fail if the underlying 32-bit
// vector is full; this can be fixed if necessary.
private inline_for_extraction
val mt_not_full_nst: mtv:merkle_tree -> Tot bool
let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max
val mt_not_full: HS.mem -> mt_p -> GTot bool
let mt_not_full h mt = mt_not_full_nst (B.get h mt 0)
/// (Memory) Safety
val offset_of: i:index_t -> Tot index_t
let offset_of i = if i % 2ul = 0ul then i else i - 1ul
// `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1`
// at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid
// element.
inline_for_extraction noextract
val mt_safe_elts:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
GTot Type0 (decreases (32 - U32.v lv))
let rec mt_safe_elts #hsz h lv hs i j =
if lv = merkle_tree_size_lg then true
else (let ofs = offset_of i in
V.size_of (V.get h hs lv) == j - ofs /\
mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))
#push-options "--initial_fuel 1 --max_fuel 1"
val mt_safe_elts_constr:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\
mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)))
(ensures (mt_safe_elts #hsz h lv hs i j))
let mt_safe_elts_constr #_ h lv hs i j = ()
val mt_safe_elts_head:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (mt_safe_elts #hsz h lv hs i j))
(ensures (V.size_of (V.get h hs lv) == j - offset_of i))
let mt_safe_elts_head #_ h lv hs i j = ()
val mt_safe_elts_rec:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (mt_safe_elts #hsz h lv hs i j))
(ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)))
let mt_safe_elts_rec #_ h lv hs i j = ()
val mt_safe_elts_init:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
Lemma (requires (V.forall_ h hs lv (V.size_of hs)
(fun hv -> V.size_of hv = 0ul)))
(ensures (mt_safe_elts #hsz h lv hs 0ul 0ul))
(decreases (32 - U32.v lv))
let rec mt_safe_elts_init #hsz h lv hs =
if lv = merkle_tree_size_lg then ()
else mt_safe_elts_init #hsz h (lv + 1ul) hs
#pop-options
val mt_safe_elts_preserved:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (V.live h0 hs /\
mt_safe_elts #hsz h0 lv hs i j /\
loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\
modifies p h0 h1))
(ensures (mt_safe_elts #hsz h1 lv hs i j))
(decreases (32 - U32.v lv))
[SMTPat (V.live h0 hs);
SMTPat (mt_safe_elts #hsz h0 lv hs i j);
SMTPat (loc_disjoint p (RV.loc_rvector hs));
SMTPat (modifies p h0 h1)]
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 =
if lv = merkle_tree_size_lg then ()
else (V.get_preserved hs lv p h0 h1;
mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1)
#pop-options
// `mt_safe` is the invariant of a Merkle tree through its lifetime.
// It includes liveness, regionality, disjointness (to each data structure),
// and valid element access (`mt_safe_elts`).
inline_for_extraction noextract
val mt_safe: HS.mem -> mt_p -> GTot Type0
let mt_safe h mt =
B.live h mt /\ B.freeable mt /\
(let mtv = B.get h mt 0 in
// Liveness & Accessibility
RV.rv_inv h (MT?.hs mtv) /\
RV.rv_inv h (MT?.rhs mtv) /\
Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\
mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\
// Regionality
HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\
HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\
HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\
HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\
HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\
HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv)))
// Since a Merkle tree satisfies regionality, it's ok to take all regions from
// a tree pointer as a location of the tree.
val mt_loc: mt_p -> GTot loc
let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt)
val mt_safe_preserved:
mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (mt_safe h0 mt /\
loc_disjoint p (mt_loc mt) /\
modifies p h0 h1))
(ensures (B.get h0 mt 0 == B.get h1 mt 0 /\
mt_safe h1 mt))
let mt_safe_preserved mt p h0 h1 =
assert (loc_includes (mt_loc mt) (B.loc_buffer mt));
let mtv = B.get h0 mt 0 in
assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv)));
assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv)));
assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv)));
assert (loc_includes (mt_loc mt)
(B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv))));
RV.rv_inv_preserved (MT?.hs mtv) p h0 h1;
RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1;
V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv));
mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1
/// Lifting to a high-level Merkle tree structure
val mt_safe_elts_spec:
#hsz:hash_size_t ->
h:HS.mem ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{j >= i} ->
Lemma (requires (RV.rv_inv h hs /\
mt_safe_elts #hsz h lv hs i j))
(ensures (MTH.hs_wf_elts #(U32.v hsz)
(U32.v lv) (RV.as_seq h hs)
(U32.v i) (U32.v j)))
(decreases (32 - U32.v lv))
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let rec mt_safe_elts_spec #_ h lv hs i j =
if lv = merkle_tree_size_lg then ()
else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul)
#pop-options
val merkle_tree_lift:
h:HS.mem ->
mtv:merkle_tree{
RV.rv_inv h (MT?.hs mtv) /\
RV.rv_inv h (MT?.rhs mtv) /\
Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\
mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} ->
GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r})
let merkle_tree_lift h mtv =
mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv);
MTH.MT #(U32.v (MT?.hash_size mtv))
(U32.v (MT?.i mtv))
(U32.v (MT?.j mtv))
(RV.as_seq h (MT?.hs mtv))
(MT?.rhs_ok mtv)
(RV.as_seq h (MT?.rhs mtv))
(Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv))
(Ghost.reveal (MT?.hash_spec mtv))
val mt_lift:
h:HS.mem -> mt:mt_p{mt_safe h mt} ->
GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r})
let mt_lift h mt =
merkle_tree_lift h (B.get h mt 0)
val mt_preserved:
mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (mt_safe h0 mt /\
loc_disjoint p (mt_loc mt) /\
modifies p h0 h1))
(ensures (mt_safe_preserved mt p h0 h1;
mt_lift h0 mt == mt_lift h1 mt))
let mt_preserved mt p h0 h1 =
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(B.loc_buffer mt));
B.modifies_buffer_elim mt p h0 h1;
assert (B.get h0 mt 0 == B.get h1 mt 0);
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(RV.loc_rvector (MT?.hs (B.get h0 mt 0))));
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(RV.loc_rvector (MT?.rhs (B.get h0 mt 0))));
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(B.loc_buffer (MT?.mroot (B.get h0 mt 0))));
RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1;
RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1;
B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1
/// Construction
// Note that the public function for creation is `mt_create` defined below,
// which builds a tree with an initial hash.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
private
val create_empty_mt:
hash_size:hash_size_t ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) ->
hash_fun:hash_fun_t #hash_size #hash_spec ->
r:HST.erid ->
HST.ST mt_p
(requires (fun _ -> true))
(ensures (fun h0 mt h1 ->
let dmt = B.get h1 mt 0 in
// memory safety
B.frameOf mt = r /\
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
mt_not_full h1 mt /\
// correctness
MT?.hash_size dmt = hash_size /\
MT?.offset dmt = 0UL /\
merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ()))
let create_empty_mt hsz hash_spec hash_fun r =
[@inline_let] let hrg = hreg hsz in
[@inline_let] let hvrg = hvreg hsz in
[@inline_let] let hvvrg = hvvreg hsz in
let hs_region = HST.new_region r in
let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in
let h0 = HST.get () in
mt_safe_elts_init #hsz h0 0ul hs;
let rhs_region = HST.new_region r in
let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in
let h1 = HST.get () in
assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz)));
RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1;
RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1;
V.loc_vector_within_included hs 0ul (V.size_of hs);
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1;
let mroot_region = HST.new_region r in
let mroot = rg_alloc hrg mroot_region in
let h2 = HST.get () in
RV.as_seq_preserved hs loc_none h1 h2;
RV.as_seq_preserved rhs loc_none h1 h2;
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2;
let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in
let h3 = HST.get () in
RV.as_seq_preserved hs loc_none h2 h3;
RV.as_seq_preserved rhs loc_none h2 h3;
Rgl?.r_sep hrg mroot loc_none h2 h3;
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3;
mt
#pop-options
/// Destruction (free)
val mt_free: mt:mt_p ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt))
(ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1))
#push-options "--z3rlimit 100"
let mt_free mt =
let mtv = !*mt in
RV.free (MT?.hs mtv);
RV.free (MT?.rhs mtv);
[@inline_let] let rg = hreg (MT?.hash_size mtv) in
rg_free rg (MT?.mroot mtv);
B.free mt
#pop-options
/// Insertion
private
val as_seq_sub_upd:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
h:HS.mem -> rv:rvector #a #rst rg ->
i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg ->
Lemma (requires (RV.rv_inv h rv))
(ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v)
(S.append
(RV.as_seq_sub h rv 0ul i)
(S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))))))
#push-options "--z3rlimit 20"
let as_seq_sub_upd #a #rst #rg h rv i v =
Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v;
Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v;
RV.as_seq_seq_slice rg h (V.as_seq h rv)
0 (U32.v (V.size_of rv)) 0 (U32.v i);
assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i))
(RV.as_seq_sub h rv 0ul i));
RV.as_seq_seq_slice rg h (V.as_seq h rv)
0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv));
assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)))
(RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)));
assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v)
#pop-options
// `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying
// and pushing its content to `hs[lv]`. For detailed insertion procedure, see
// `insert_` and `mt_insert`.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1"
private
inline_for_extraction
val hash_vv_insert_copy:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (V.frameOf hs) (B.frameOf v) /\
mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 v /\
V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\
V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\
mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\
RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) ==
RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.hashess_insert
(U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\
S.equal (S.index (RV.as_seq h1 hs) (U32.v lv))
(S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"MerkleTree.New.High.fst.checked",
"MerkleTree.Low.VectorExtras.fst.checked",
"MerkleTree.Low.Hashfunctions.fst.checked",
"MerkleTree.Low.Datastructures.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.Instances.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Monotonic.HyperHeap.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.All.fst.checked",
"EverCrypt.Helpers.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.Low.fst"
} | [
{
"abbrev": false,
"full_module": "MerkleTree.Low.VectorExtras",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low.Hashfunctions",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low.Datastructures",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "MerkleTree.New.High",
"short_module": "MTH"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Regional.Instances",
"short_module": "RVI"
},
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.HyperHeap",
"short_module": "HH"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": "MHS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.Regional.Instances",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
lv: LowStar.Vector.uint32_t{lv < MerkleTree.Low.merkle_tree_size_lg} ->
i: FStar.Ghost.erased MerkleTree.Low.index_t ->
j:
MerkleTree.Low.index_t
{ FStar.Ghost.reveal i <= j && FStar.UInt32.v j < Prims.pow2 (32 - FStar.UInt32.v lv) - 1 &&
j < MerkleTree.Low.uint32_32_max } ->
hs:
MerkleTree.Low.Datastructures.hash_vv hsz
{LowStar.Vector.size_of hs = MerkleTree.Low.merkle_tree_size_lg} ->
v: MerkleTree.Low.Datastructures.hash
-> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"MerkleTree.Low.Datastructures.hash_size_t",
"LowStar.Vector.uint32_t",
"Prims.b2t",
"FStar.Integers.op_Less",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"MerkleTree.Low.merkle_tree_size_lg",
"FStar.Ghost.erased",
"MerkleTree.Low.index_t",
"Prims.op_AmpAmp",
"FStar.Integers.op_Less_Equals",
"FStar.Ghost.reveal",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"FStar.UInt32.v",
"FStar.Integers.op_Subtraction",
"Prims.pow2",
"MerkleTree.Low.uint32_32_max",
"MerkleTree.Low.Datastructures.hash_vv",
"Prims.op_Equality",
"LowStar.Vector.size_of",
"MerkleTree.Low.Datastructures.hash_vec",
"MerkleTree.Low.Datastructures.hash",
"MerkleTree.Low.as_seq_sub_upd",
"MerkleTree.Low.Datastructures.hvreg",
"LowStar.RVector.as_seq",
"MerkleTree.Low.Datastructures.hreg",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"LowStar.Regional.__proj__Rgl__item__repr",
"FStar.Seq.Base.append",
"LowStar.RVector.as_seq_sub",
"FStar.UInt32.__uint_to_t",
"FStar.Seq.Base.cons",
"FStar.Integers.op_Plus",
"LowStar.RVector.as_seq_sub_preserved",
"LowStar.RVector.loc_rvector",
"MerkleTree.Low.mt_safe_elts_preserved",
"FStar.Integers.op_Slash",
"LowStar.Vector.loc_vector_within",
"Prims.eq2",
"FStar.UInt32.t",
"LowStar.Vector.get",
"MerkleTree.Low.offset_of",
"LowStar.RVector.rv_loc_elems_preserved",
"LowStar.Regional.__proj__Rgl__item__r_sep",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.RVector.rs_loc_elem",
"LowStar.Vector.as_seq",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.RVector.assign",
"FStar.Seq.Properties.snoc",
"LowStar.Regional.__proj__Rgl__item__r_repr",
"LowStar.RVector.rv_elems_inv",
"LowStar.RVector.rv_elems_inv_preserved",
"LowStar.RVector.rs_loc_elems_parent_disj",
"LowStar.Vector.frameOf",
"LowStar.RVector.rs_loc_elems_elem_disj",
"LowStar.Vector.loc_vector_within_disjoint",
"LowStar.Vector.loc_vector_within_included",
"LowStar.Vector.forall2_forall_right",
"FStar.Monotonic.HyperHeap.disjoint",
"LowStar.Regional.__proj__Rgl__item__region_of",
"LowStar.Vector.forall2_forall_left",
"LowStar.RVector.rvector",
"LowStar.RVector.insert_copy",
"MerkleTree.Low.Datastructures.hcpy",
"Prims.op_Negation",
"LowStar.Vector.is_full",
"LowStar.Vector.index",
"MerkleTree.Low.mt_safe_elts_rec"
] | [] | false | true | false | false | false | let hash_vv_insert_copy #hsz lv i j hs v =
| let hh0 = HST.get () in
mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j;
let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in
let hh1 = HST.get () in
V.forall2_forall_left hh0
hs
0ul
(V.size_of hs)
lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0
hs
0ul
(V.size_of hs)
lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1) (Rgl?.region_of (hvreg hsz) b2));
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
RV.rv_loc_elems_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i));
mt_safe_elts_preserved (lv + 1ul)
hs
(Ghost.reveal i / 2ul)
(j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv))
hh0
hh1;
RV.rs_loc_elems_elem_disj (hvreg hsz)
(V.as_seq hh0 hs)
(V.frameOf hs)
0
(U32.v (V.size_of hs))
0
(U32.v lv)
(U32.v lv);
RV.rs_loc_elems_parent_disj (hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs) 0 (U32.v lv);
RV.rv_elems_inv_preserved hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj (hvreg hsz)
(V.as_seq hh0 hs)
(V.frameOf hs)
0
(U32.v (V.size_of hs))
(U32.v lv + 1)
(U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj (hvreg hsz)
(V.as_seq hh0 hs)
(V.frameOf hs)
(U32.v lv + 1)
(U32.v (V.size_of hs));
RV.rv_elems_inv_preserved hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
assert (S.equal (RV.as_seq hh1 ihv)
(S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v)));
RV.assign hs lv ihv;
let hh2 = HST.get () in
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
hh0
hh2);
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2;
RV.rv_loc_elems_preserved hs
(lv + 1ul)
(V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul))
hh1
hh2;
assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i));
mt_safe_elts_preserved (lv + 1ul)
hs
(Ghost.reveal i / 2ul)
(j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul))
hh1
hh2;
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append (RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 ihv) (RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv) | false |
Pulse.Soundness.Comp.fst | Pulse.Soundness.Comp.stc_soundness | val stc_soundness
(#g:stt_env)
(#st:st_comp)
(d_st:st_comp_typing g st)
: GTot (RT.tot_typing ( elab_env g)
(elab_term st.res)
(RT.tm_type st.u) &
RT.tot_typing (elab_env g)
(elab_term st.pre)
vprop_tm &
RT.tot_typing (elab_env g)
(mk_abs (elab_term st.res) R.Q_Explicit
(elab_term st.post))
(post1_type_bind (elab_term st.res))) | val stc_soundness
(#g:stt_env)
(#st:st_comp)
(d_st:st_comp_typing g st)
: GTot (RT.tot_typing ( elab_env g)
(elab_term st.res)
(RT.tm_type st.u) &
RT.tot_typing (elab_env g)
(elab_term st.pre)
vprop_tm &
RT.tot_typing (elab_env g)
(mk_abs (elab_term st.res) R.Q_Explicit
(elab_term st.post))
(post1_type_bind (elab_term st.res))) | let stc_soundness
(#g:stt_env)
(#st:st_comp)
(d_st:st_comp_typing g st)
: GTot (RT.tot_typing (elab_env g)
(elab_term st.res)
(RT.tm_type st.u) &
RT.tot_typing (elab_env g)
(elab_term st.pre)
vprop_tm &
RT.tot_typing (elab_env g)
(mk_abs (elab_term st.res) R.Q_Explicit
(elab_term st.post))
(post1_type_bind (elab_term st.res))) =
let STC _ st x dres dpre dpost = d_st in
let res_typing = tot_typing_soundness dres in
let pre_typing = tot_typing_soundness dpre in
calc (==) {
RT.close_term (elab_term (open_term st.post x)) x;
(==) { elab_open_commute st.post x }
RT.close_term (RT.open_term (elab_term st.post) x) x;
(==) {
elab_freevars st.post;
RT.close_open_inverse (elab_term st.post) x
}
elab_term st.post;
};
let post_typing = mk_t_abs_tot g ppname_default dres dpost in
res_typing, pre_typing, post_typing | {
"file_name": "lib/steel/pulse/Pulse.Soundness.Comp.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 58,
"start_col": 0,
"start_line": 28
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Soundness.Comp
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Elaborate.Core
open Pulse.Elaborate
open Pulse.Soundness.Common
module STT = Pulse.Soundness.STT | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.STT.fsti.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"Pulse.Elaborate.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Soundness.Comp.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Soundness.STT",
"short_module": "STT"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | d_st: Pulse.Typing.st_comp_typing g st
-> Prims.GTot
((FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g)
(Pulse.Elaborate.Pure.elab_term (Mkst_comp?.res st))
(FStar.Reflection.Typing.tm_type (Mkst_comp?.u st)) *
FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g)
(Pulse.Elaborate.Pure.elab_term (Mkst_comp?.pre st))
Pulse.Reflection.Util.vprop_tm) *
FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g)
(Pulse.Reflection.Util.mk_abs (Pulse.Elaborate.Pure.elab_term (Mkst_comp?.res st))
FStar.Stubs.Reflection.V2.Data.Q_Explicit
(Pulse.Elaborate.Pure.elab_term (Mkst_comp?.post st)))
(Pulse.Soundness.Common.post1_type_bind (Pulse.Elaborate.Pure.elab_term (Mkst_comp?.res st))
)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Soundness.Common.stt_env",
"Pulse.Syntax.Base.st_comp",
"Pulse.Typing.st_comp_typing",
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.var",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_None",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.Env.lookup",
"Prims.l_not",
"FStar.Set.mem",
"Pulse.Syntax.Naming.freevars",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Pulse.Typing.universe_of",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.Env.push_binding",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Syntax.Naming.open_term",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Reflection.Typing.tot_typing",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term",
"FStar.Reflection.Typing.tm_type",
"Pulse.Reflection.Util.vprop_tm",
"Pulse.Reflection.Util.mk_abs",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Pulse.Soundness.Common.post1_type_bind",
"Pulse.Reflection.Util.mk_abs_with_name",
"Pulse.Syntax.Base.__proj__Mkppname__item__name",
"Pulse.Elaborate.Pure.elab_qual",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_arrow",
"Pulse.Syntax.Base.mk_binder_ppname",
"Pulse.Syntax.Naming.close_comp",
"Pulse.Syntax.Base.C_Tot",
"Pulse.Soundness.Common.mk_t_abs_tot",
"Prims.unit",
"FStar.Calc.calc_finish",
"FStar.Stubs.Reflection.Types.term",
"Prims.eq2",
"FStar.Reflection.Typing.close_term",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Reflection.Typing.open_term",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Pulse.Elaborate.elab_open_commute",
"Prims.squash",
"FStar.Reflection.Typing.close_open_inverse",
"Pulse.Elaborate.elab_freevars",
"Pulse.Soundness.Common.tot_typing_soundness",
"Pulse.Syntax.Pure.tm_type",
"FStar.Pervasives.Native.tuple3"
] | [] | false | false | false | false | false | let stc_soundness (#g: stt_env) (#st: st_comp) (d_st: st_comp_typing g st)
: GTot
(RT.tot_typing (elab_env g) (elab_term st.res) (RT.tm_type st.u) &
RT.tot_typing (elab_env g) (elab_term st.pre) vprop_tm &
RT.tot_typing (elab_env g)
(mk_abs (elab_term st.res) R.Q_Explicit (elab_term st.post))
(post1_type_bind (elab_term st.res))) =
| let STC _ st x dres dpre dpost = d_st in
let res_typing = tot_typing_soundness dres in
let pre_typing = tot_typing_soundness dpre in
calc ( == ) {
RT.close_term (elab_term (open_term st.post x)) x;
( == ) { elab_open_commute st.post x }
RT.close_term (RT.open_term (elab_term st.post) x) x;
( == ) { (elab_freevars st.post;
RT.close_open_inverse (elab_term st.post) x) }
elab_term st.post;
};
let post_typing = mk_t_abs_tot g ppname_default dres dpost in
res_typing, pre_typing, post_typing | false |
MerkleTree.Low.fst | MerkleTree.Low.mt_verify_ | val mt_verify_:
#hsz:hash_size_t ->
#hash_spec:MTS.hash_fun_t #(U32.v hsz) ->
k:index_t ->
j:index_t{k <= j} ->
mtr:HH.rid ->
p:const_path_p ->
ppos:uint32_t ->
acc:hash #hsz ->
actd:bool ->
hash_fun:hash_fun_t #hsz #hash_spec ->
HST.ST unit
(requires (fun h0 ->
let p = CB.cast p in
path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 acc /\
Path?.hash_size (B.get h0 p 0) = hsz /\
HH.disjoint (B.frameOf p) (B.frameOf acc) /\
HH.disjoint mtr (B.frameOf acc) /\
// Below is a very relaxed condition,
// but sufficient to ensure (+) for uint32_t is sound.
ppos <= 64ul - mt_path_length 0ul k j actd /\
ppos + mt_path_length 0ul k j actd <= V.size_of (phashes h0 p)))
(ensures (fun h0 _ h1 ->
let p = CB.cast p in
// memory safety
modifies (B.loc_all_regions_from false (B.frameOf acc)) h0 h1 /\
Rgl?.r_inv (hreg hsz) h1 acc /\
// correctness
Rgl?.r_repr (hreg hsz) h1 acc ==
MTH.mt_verify_ #(U32.v hsz) #hash_spec (U32.v k) (U32.v j) (lift_path h0 mtr p)
(U32.v ppos) (Rgl?.r_repr (hreg hsz) h0 acc) actd)) | val mt_verify_:
#hsz:hash_size_t ->
#hash_spec:MTS.hash_fun_t #(U32.v hsz) ->
k:index_t ->
j:index_t{k <= j} ->
mtr:HH.rid ->
p:const_path_p ->
ppos:uint32_t ->
acc:hash #hsz ->
actd:bool ->
hash_fun:hash_fun_t #hsz #hash_spec ->
HST.ST unit
(requires (fun h0 ->
let p = CB.cast p in
path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 acc /\
Path?.hash_size (B.get h0 p 0) = hsz /\
HH.disjoint (B.frameOf p) (B.frameOf acc) /\
HH.disjoint mtr (B.frameOf acc) /\
// Below is a very relaxed condition,
// but sufficient to ensure (+) for uint32_t is sound.
ppos <= 64ul - mt_path_length 0ul k j actd /\
ppos + mt_path_length 0ul k j actd <= V.size_of (phashes h0 p)))
(ensures (fun h0 _ h1 ->
let p = CB.cast p in
// memory safety
modifies (B.loc_all_regions_from false (B.frameOf acc)) h0 h1 /\
Rgl?.r_inv (hreg hsz) h1 acc /\
// correctness
Rgl?.r_repr (hreg hsz) h1 acc ==
MTH.mt_verify_ #(U32.v hsz) #hash_spec (U32.v k) (U32.v j) (lift_path h0 mtr p)
(U32.v ppos) (Rgl?.r_repr (hreg hsz) h0 acc) actd)) | let rec mt_verify_ #hsz #hash_spec k j mtr p ppos acc actd hash_fun =
let ncp:path_p = CB.cast p in
let hh0 = HST.get () in
if j = 0ul then ()
else (let nactd = actd || (j % 2ul = 1ul) in
if k % 2ul = 0ul then begin
if j = k || (j = k + 1ul && not actd) then
mt_verify_ (k / 2ul) (j / 2ul) mtr p ppos acc nactd hash_fun
else begin
let ncpd = !*ncp in
let phash = V.index (Path?.hashes ncpd) ppos in
hash_fun acc phash acc;
let hh1 = HST.get () in
path_preserved mtr ncp
(B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
lift_path_index hh0 mtr ncp ppos;
assert (Rgl?.r_repr (hreg hsz) hh1 acc ==
hash_spec (Rgl?.r_repr (hreg hsz) hh0 acc)
(S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos)));
mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun
end
end
else begin
let ncpd = !*ncp in
let phash = V.index (Path?.hashes ncpd) ppos in
hash_fun phash acc acc;
let hh1 = HST.get () in
path_preserved mtr ncp
(B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
lift_path_index hh0 mtr ncp ppos;
assert (Rgl?.r_repr (hreg hsz) hh1 acc ==
hash_spec (S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos))
(Rgl?.r_repr (hreg hsz) hh0 acc));
mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun
end) | {
"file_name": "src/MerkleTree.Low.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 11,
"end_line": 2883,
"start_col": 0,
"start_line": 2849
} | module MerkleTree.Low
open EverCrypt.Helpers
open FStar.All
open FStar.Integers
open FStar.Mul
open LowStar.Buffer
open LowStar.BufferOps
open LowStar.Vector
open LowStar.Regional
open LowStar.RVector
open LowStar.Regional.Instances
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MHS = FStar.Monotonic.HyperStack
module HH = FStar.Monotonic.HyperHeap
module B = LowStar.Buffer
module CB = LowStar.ConstBuffer
module V = LowStar.Vector
module RV = LowStar.RVector
module RVI = LowStar.Regional.Instances
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module MTH = MerkleTree.New.High
module MTS = MerkleTree.Spec
open Lib.IntTypes
open MerkleTree.Low.Datastructures
open MerkleTree.Low.Hashfunctions
open MerkleTree.Low.VectorExtras
#set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE}
/// Low-level Merkle tree data structure
///
// NOTE: because of a lack of 64-bit LowStar.Buffer support, currently
// we cannot change below to some other types.
type index_t = uint32_t
let uint32_32_max = 4294967295ul
inline_for_extraction
let uint32_max = 4294967295UL
let uint64_max = 18446744073709551615UL
let offset_range_limit = uint32_max
type offset_t = uint64_t
inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64
inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32
private inline_for_extraction
let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit
private inline_for_extraction
let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t =
[@inline_let] let diff = U64.sub_mod index tree in
assert (diff <= offset_range_limit);
Int.Cast.uint64_to_uint32 diff
private inline_for_extraction
let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i)
private inline_for_extraction
let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) =
U64.add tree (u32_64 i)
inline_for_extraction val merkle_tree_size_lg: uint32_t
let merkle_tree_size_lg = 32ul
// A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate
// a Merkle path for each element from the index `i` to `j-1`.
// - Parameters
// `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values.
// `rhs_ok`: to check the rightmost hashes are up-to-date
// `rhs`: a store for "rightmost" hashes, manipulated only when required to
// calculate some merkle paths that need the rightmost hashes
// as a part of them.
// `mroot`: during the construction of `rhs` we can also calculate the Merkle
// root of the tree. If `rhs_ok` is true then it has the up-to-date
// root value.
noeq type merkle_tree =
| MT: hash_size:hash_size_t ->
offset:offset_t ->
i:index_t -> j:index_t{i <= j /\ add64_fits offset j} ->
hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} ->
rhs_ok:bool ->
rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} ->
mroot:hash #hash_size ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) ->
hash_fun:hash_fun_t #hash_size #hash_spec ->
merkle_tree
type mt_p = B.pointer merkle_tree
type const_mt_p = const_pointer merkle_tree
inline_for_extraction
let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool =
j >= i && add64_fits offset j &&
V.size_of hs = merkle_tree_size_lg &&
V.size_of rhs = merkle_tree_size_lg
// The maximum number of currently held elements in the tree is (2^32 - 1).
// cwinter: even when using 64-bit indices, we fail if the underlying 32-bit
// vector is full; this can be fixed if necessary.
private inline_for_extraction
val mt_not_full_nst: mtv:merkle_tree -> Tot bool
let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max
val mt_not_full: HS.mem -> mt_p -> GTot bool
let mt_not_full h mt = mt_not_full_nst (B.get h mt 0)
/// (Memory) Safety
val offset_of: i:index_t -> Tot index_t
let offset_of i = if i % 2ul = 0ul then i else i - 1ul
// `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1`
// at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid
// element.
inline_for_extraction noextract
val mt_safe_elts:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
GTot Type0 (decreases (32 - U32.v lv))
let rec mt_safe_elts #hsz h lv hs i j =
if lv = merkle_tree_size_lg then true
else (let ofs = offset_of i in
V.size_of (V.get h hs lv) == j - ofs /\
mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))
#push-options "--initial_fuel 1 --max_fuel 1"
val mt_safe_elts_constr:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\
mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)))
(ensures (mt_safe_elts #hsz h lv hs i j))
let mt_safe_elts_constr #_ h lv hs i j = ()
val mt_safe_elts_head:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (mt_safe_elts #hsz h lv hs i j))
(ensures (V.size_of (V.get h hs lv) == j - offset_of i))
let mt_safe_elts_head #_ h lv hs i j = ()
val mt_safe_elts_rec:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (mt_safe_elts #hsz h lv hs i j))
(ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)))
let mt_safe_elts_rec #_ h lv hs i j = ()
val mt_safe_elts_init:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
Lemma (requires (V.forall_ h hs lv (V.size_of hs)
(fun hv -> V.size_of hv = 0ul)))
(ensures (mt_safe_elts #hsz h lv hs 0ul 0ul))
(decreases (32 - U32.v lv))
let rec mt_safe_elts_init #hsz h lv hs =
if lv = merkle_tree_size_lg then ()
else mt_safe_elts_init #hsz h (lv + 1ul) hs
#pop-options
val mt_safe_elts_preserved:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (V.live h0 hs /\
mt_safe_elts #hsz h0 lv hs i j /\
loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\
modifies p h0 h1))
(ensures (mt_safe_elts #hsz h1 lv hs i j))
(decreases (32 - U32.v lv))
[SMTPat (V.live h0 hs);
SMTPat (mt_safe_elts #hsz h0 lv hs i j);
SMTPat (loc_disjoint p (RV.loc_rvector hs));
SMTPat (modifies p h0 h1)]
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 =
if lv = merkle_tree_size_lg then ()
else (V.get_preserved hs lv p h0 h1;
mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1)
#pop-options
// `mt_safe` is the invariant of a Merkle tree through its lifetime.
// It includes liveness, regionality, disjointness (to each data structure),
// and valid element access (`mt_safe_elts`).
inline_for_extraction noextract
val mt_safe: HS.mem -> mt_p -> GTot Type0
let mt_safe h mt =
B.live h mt /\ B.freeable mt /\
(let mtv = B.get h mt 0 in
// Liveness & Accessibility
RV.rv_inv h (MT?.hs mtv) /\
RV.rv_inv h (MT?.rhs mtv) /\
Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\
mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\
// Regionality
HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\
HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\
HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\
HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\
HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\
HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv)))
// Since a Merkle tree satisfies regionality, it's ok to take all regions from
// a tree pointer as a location of the tree.
val mt_loc: mt_p -> GTot loc
let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt)
val mt_safe_preserved:
mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (mt_safe h0 mt /\
loc_disjoint p (mt_loc mt) /\
modifies p h0 h1))
(ensures (B.get h0 mt 0 == B.get h1 mt 0 /\
mt_safe h1 mt))
let mt_safe_preserved mt p h0 h1 =
assert (loc_includes (mt_loc mt) (B.loc_buffer mt));
let mtv = B.get h0 mt 0 in
assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv)));
assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv)));
assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv)));
assert (loc_includes (mt_loc mt)
(B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv))));
RV.rv_inv_preserved (MT?.hs mtv) p h0 h1;
RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1;
V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv));
mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1
/// Lifting to a high-level Merkle tree structure
val mt_safe_elts_spec:
#hsz:hash_size_t ->
h:HS.mem ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{j >= i} ->
Lemma (requires (RV.rv_inv h hs /\
mt_safe_elts #hsz h lv hs i j))
(ensures (MTH.hs_wf_elts #(U32.v hsz)
(U32.v lv) (RV.as_seq h hs)
(U32.v i) (U32.v j)))
(decreases (32 - U32.v lv))
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let rec mt_safe_elts_spec #_ h lv hs i j =
if lv = merkle_tree_size_lg then ()
else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul)
#pop-options
val merkle_tree_lift:
h:HS.mem ->
mtv:merkle_tree{
RV.rv_inv h (MT?.hs mtv) /\
RV.rv_inv h (MT?.rhs mtv) /\
Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\
mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} ->
GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r})
let merkle_tree_lift h mtv =
mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv);
MTH.MT #(U32.v (MT?.hash_size mtv))
(U32.v (MT?.i mtv))
(U32.v (MT?.j mtv))
(RV.as_seq h (MT?.hs mtv))
(MT?.rhs_ok mtv)
(RV.as_seq h (MT?.rhs mtv))
(Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv))
(Ghost.reveal (MT?.hash_spec mtv))
val mt_lift:
h:HS.mem -> mt:mt_p{mt_safe h mt} ->
GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r})
let mt_lift h mt =
merkle_tree_lift h (B.get h mt 0)
val mt_preserved:
mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (mt_safe h0 mt /\
loc_disjoint p (mt_loc mt) /\
modifies p h0 h1))
(ensures (mt_safe_preserved mt p h0 h1;
mt_lift h0 mt == mt_lift h1 mt))
let mt_preserved mt p h0 h1 =
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(B.loc_buffer mt));
B.modifies_buffer_elim mt p h0 h1;
assert (B.get h0 mt 0 == B.get h1 mt 0);
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(RV.loc_rvector (MT?.hs (B.get h0 mt 0))));
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(RV.loc_rvector (MT?.rhs (B.get h0 mt 0))));
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(B.loc_buffer (MT?.mroot (B.get h0 mt 0))));
RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1;
RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1;
B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1
/// Construction
// Note that the public function for creation is `mt_create` defined below,
// which builds a tree with an initial hash.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
private
val create_empty_mt:
hash_size:hash_size_t ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) ->
hash_fun:hash_fun_t #hash_size #hash_spec ->
r:HST.erid ->
HST.ST mt_p
(requires (fun _ -> true))
(ensures (fun h0 mt h1 ->
let dmt = B.get h1 mt 0 in
// memory safety
B.frameOf mt = r /\
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
mt_not_full h1 mt /\
// correctness
MT?.hash_size dmt = hash_size /\
MT?.offset dmt = 0UL /\
merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ()))
let create_empty_mt hsz hash_spec hash_fun r =
[@inline_let] let hrg = hreg hsz in
[@inline_let] let hvrg = hvreg hsz in
[@inline_let] let hvvrg = hvvreg hsz in
let hs_region = HST.new_region r in
let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in
let h0 = HST.get () in
mt_safe_elts_init #hsz h0 0ul hs;
let rhs_region = HST.new_region r in
let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in
let h1 = HST.get () in
assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz)));
RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1;
RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1;
V.loc_vector_within_included hs 0ul (V.size_of hs);
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1;
let mroot_region = HST.new_region r in
let mroot = rg_alloc hrg mroot_region in
let h2 = HST.get () in
RV.as_seq_preserved hs loc_none h1 h2;
RV.as_seq_preserved rhs loc_none h1 h2;
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2;
let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in
let h3 = HST.get () in
RV.as_seq_preserved hs loc_none h2 h3;
RV.as_seq_preserved rhs loc_none h2 h3;
Rgl?.r_sep hrg mroot loc_none h2 h3;
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3;
mt
#pop-options
/// Destruction (free)
val mt_free: mt:mt_p ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt))
(ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1))
#push-options "--z3rlimit 100"
let mt_free mt =
let mtv = !*mt in
RV.free (MT?.hs mtv);
RV.free (MT?.rhs mtv);
[@inline_let] let rg = hreg (MT?.hash_size mtv) in
rg_free rg (MT?.mroot mtv);
B.free mt
#pop-options
/// Insertion
private
val as_seq_sub_upd:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
h:HS.mem -> rv:rvector #a #rst rg ->
i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg ->
Lemma (requires (RV.rv_inv h rv))
(ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v)
(S.append
(RV.as_seq_sub h rv 0ul i)
(S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))))))
#push-options "--z3rlimit 20"
let as_seq_sub_upd #a #rst #rg h rv i v =
Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v;
Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v;
RV.as_seq_seq_slice rg h (V.as_seq h rv)
0 (U32.v (V.size_of rv)) 0 (U32.v i);
assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i))
(RV.as_seq_sub h rv 0ul i));
RV.as_seq_seq_slice rg h (V.as_seq h rv)
0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv));
assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)))
(RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)));
assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v)
#pop-options
// `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying
// and pushing its content to `hs[lv]`. For detailed insertion procedure, see
// `insert_` and `mt_insert`.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1"
private
inline_for_extraction
val hash_vv_insert_copy:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (V.frameOf hs) (B.frameOf v) /\
mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 v /\
V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\
V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\
mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\
RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) ==
RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.hashess_insert
(U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\
S.equal (S.index (RV.as_seq h1 hs) (U32.v lv))
(S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv))
(Rgl?.r_repr (hreg hsz) h0 v))))
let hash_vv_insert_copy #hsz lv i j hs v =
let hh0 = HST.get () in
mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j;
/// 1) Insert an element at the level `lv`, where the new vector is not yet
/// connected to `hs`.
let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in
let hh1 = HST.get () in
// 1-0) Basic disjointness conditions
V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
// 1-1) For the `modifies` postcondition.
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
// 1-2) Preservation
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-3) For `mt_safe_elts`
assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet
// 1-4) For the `rv_inv` postcondition
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v lv);
RV.rv_elems_inv_preserved
hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs))
(U32.v lv + 1) (U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
(U32.v lv + 1) (U32.v (V.size_of hs));
RV.rv_elems_inv_preserved
hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
// assert (rv_itself_inv hh1 hs);
// assert (elems_reg hh1 hs);
// 1-5) Correctness
assert (S.equal (RV.as_seq hh1 ihv)
(S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v)));
/// 2) Assign the updated vector to `hs` at the level `lv`.
RV.assign hs lv ihv;
let hh2 = HST.get () in
// 2-1) For the `modifies` postcondition.
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2);
// 2-2) Preservation
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-3) For `mt_safe_elts`
assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i));
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-4) Correctness
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append
(RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 ihv)
(RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv)
#pop-options
private
val insert_index_helper_even:
lv:uint32_t{lv < merkle_tree_size_lg} ->
j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} ->
Lemma (requires (j % 2ul <> 1ul))
(ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul))
let insert_index_helper_even lv j = ()
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
private
val insert_index_helper_odd:
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:index_t ->
j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} ->
Lemma (requires (j % 2ul = 1ul /\
j < uint32_32_max))
(ensures (U32.v j % 2 = 1 /\
U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\
(j + 1ul) / 2ul == j / 2ul + 1ul /\
j - offset_of i > 0ul))
let insert_index_helper_odd lv i j = ()
#pop-options
private
val loc_union_assoc_4:
a:loc -> b:loc -> c:loc -> d:loc ->
Lemma (loc_union (loc_union a b) (loc_union c d) ==
loc_union (loc_union a c) (loc_union b d))
let loc_union_assoc_4 a b c d =
loc_union_assoc (loc_union a b) c d;
loc_union_assoc a b c;
loc_union_assoc a c b;
loc_union_assoc (loc_union a c) b d
private
val insert_modifies_rec_helper:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
aloc:loc ->
h:HS.mem ->
Lemma (loc_union
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
aloc)
(loc_union
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
aloc) ==
loc_union
(loc_union
(RV.rv_loc_elems h hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
aloc)
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let insert_modifies_rec_helper #hsz lv hs aloc h =
assert (V.loc_vector_within hs lv (V.size_of hs) ==
loc_union (V.loc_vector_within hs lv (lv + 1ul))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)));
RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs));
assert (RV.rv_loc_elems h hs lv (V.size_of hs) ==
loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)));
// Applying some association rules...
loc_union_assoc
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) aloc
(loc_union
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
aloc);
loc_union_assoc
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc;
loc_union_assoc
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
aloc;
loc_union_assoc_4
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
#pop-options
private
val insert_modifies_union_loc_weakening:
l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (modifies l1 h0 h1))
(ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1))
let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 =
B.loc_includes_union_l l1 l2 l1;
B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2)
private
val insert_snoc_last_helper:
#a:Type -> s:S.seq a{S.length s > 0} -> v:a ->
Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s)
let insert_snoc_last_helper #a s v = ()
private
val rv_inv_rv_elems_reg:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
h:HS.mem -> rv:rvector rg ->
i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} ->
Lemma (requires (RV.rv_inv h rv))
(ensures (RV.rv_elems_reg h rv i j))
let rv_inv_rv_elems_reg #a #rst #rg h rv i j = ()
// `insert_` recursively inserts proper hashes to each level `lv` by
// accumulating a compressed hash. For example, if there are three leaf elements
// in the tree, `insert_` will change `hs` as follow:
// (`hij` is a compressed hash from `hi` to `hj`)
//
// BEFORE INSERTION AFTER INSERTION
// lv
// 0 h0 h1 h2 ====> h0 h1 h2 h3
// 1 h01 h01 h23
// 2 h03
//
private
val insert_:
#hsz:hash_size_t ->
#hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
acc:hash #hsz ->
hash_fun:hash_fun_t #hsz #hash_spec ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 acc /\
HH.disjoint (V.frameOf hs) (B.frameOf acc) /\
mt_safe_elts h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(loc_union
(RV.rv_loc_elems h0 hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 acc /\
mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\
// correctness
(mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc)))))
(decreases (U32.v j))
#push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun =
let hh0 = HST.get () in
hash_vv_insert_copy lv i j hs acc;
let hh1 = HST.get () in
// Base conditions
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i));
assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul));
if j % 2ul = 1ul
then (insert_index_helper_odd lv (Ghost.reveal i) j;
assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0);
let lvhs = V.index hs lv in
assert (U32.v (V.size_of lvhs) ==
S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1);
assert (V.size_of lvhs > 1ul);
/// 3) Update the accumulator `acc`.
hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul);
assert (Rgl?.r_inv (hreg hsz) hh1 acc);
hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc;
let hh2 = HST.get () in
// 3-1) For the `modifies` postcondition
assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2);
assert (modifies
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh0 hh2);
// 3-2) Preservation
RV.rv_inv_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.as_seq_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(B.loc_region_only false (B.frameOf acc)) hh1 hh2;
assert (RV.rv_inv hh2 hs);
assert (Rgl?.r_inv (hreg hsz) hh2 acc);
// 3-3) For `mt_safe_elts`
V.get_preserved hs lv
(B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved
// 3-4) Correctness
insert_snoc_last_helper
(RV.as_seq hh0 (V.get hh0 hs lv))
(Rgl?.r_repr (hreg hsz) hh0 acc);
assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_`
((Ghost.reveal hash_spec)
(S.last (S.index (RV.as_seq hh0 hs) (U32.v lv)))
(Rgl?.r_repr (hreg hsz) hh0 acc)));
/// 4) Recursion
insert_ (lv + 1ul)
(Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul)
hs acc hash_fun;
let hh3 = HST.get () in
// 4-0) Memory safety brought from the postcondition of the recursion
assert (RV.rv_inv hh3 hs);
assert (Rgl?.r_inv (hreg hsz) hh3 acc);
assert (modifies (loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh2 hh3);
assert (modifies
(loc_union
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc)))
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc))))
hh0 hh3);
// 4-1) For `mt_safe_elts`
rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs);
RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs);
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)));
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(B.loc_all_regions_from false (B.frameOf acc)));
V.get_preserved hs lv
(loc_union
(loc_union
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh2 hh3;
assert (V.size_of (V.get hh3 hs lv) ==
j + 1ul - offset_of (Ghost.reveal i)); // head preserved
assert (mt_safe_elts hh3 (lv + 1ul) hs
(Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion
mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul);
assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul));
// 4-2) Correctness
mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul);
assert (S.equal (RV.as_seq hh3 hs)
(MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2)
(RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc)));
mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j;
MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc);
assert (S.equal (RV.as_seq hh3 hs)
(MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))))
else (insert_index_helper_even lv j;
// memory safety
assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul));
mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul);
assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul));
assert (modifies
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
hh0 hh1);
insert_modifies_union_loc_weakening
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc))
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh0 hh1;
// correctness
mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j;
MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc);
assert (S.equal (RV.as_seq hh1 hs)
(MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))));
/// 5) Proving the postcondition after recursion
let hh4 = HST.get () in
// 5-1) For the `modifies` postcondition.
assert (modifies
(loc_union
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc)))
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc))))
hh0 hh4);
insert_modifies_rec_helper
lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0;
// 5-2) For `mt_safe_elts`
assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul));
// 5-3) Preservation
assert (RV.rv_inv hh4 hs);
assert (Rgl?.r_inv (hreg hsz) hh4 acc);
// 5-4) Correctness
mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j;
assert (S.equal (RV.as_seq hh4 hs)
(MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED
#pop-options
private inline_for_extraction
val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool
let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul)
val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool
(requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz))
(ensures (fun _ _ _ -> True))
let mt_insert_pre #hsz mt v =
let mt = !*(CB.cast mt) in
assert (MT?.hash_size mt == (MT?.hash_size mt));
mt_insert_pre_nst mt v
// `mt_insert` inserts a hash to a Merkle tree. Note that this operation
// manipulates the content in `v`, since it uses `v` as an accumulator during
// insertion.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
val mt_insert:
hsz:Ghost.erased hash_size_t ->
mt:mt_p -> v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
let dmt = B.get h0 mt 0 in
mt_safe h0 mt /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (B.frameOf mt) (B.frameOf v) /\
MT?.hash_size dmt = Ghost.reveal hsz /\
mt_insert_pre_nst dmt v))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(mt_loc mt)
(B.loc_all_regions_from false (B.frameOf v)))
h0 h1 /\
mt_safe h1 mt /\
// correctness
MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\
mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v)))
#pop-options
#push-options "--z3rlimit 40"
let mt_insert hsz mt v =
let hh0 = HST.get () in
let mtv = !*mt in
let hs = MT?.hs mtv in
let hsz = MT?.hash_size mtv in
insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv);
let hh1 = HST.get () in
RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs);
V.loc_vector_within_included hs 0ul (V.size_of hs);
RV.rv_inv_preserved
(MT?.rhs mtv)
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf v)))
hh0 hh1;
RV.as_seq_preserved
(MT?.rhs mtv)
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf v)))
hh0 hh1;
Rgl?.r_sep (hreg hsz) (MT?.mroot mtv)
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf v)))
hh0 hh1;
mt *= MT (MT?.hash_size mtv)
(MT?.offset mtv)
(MT?.i mtv)
(MT?.j mtv + 1ul)
(MT?.hs mtv)
false // `rhs` is always deprecated right after an insertion.
(MT?.rhs mtv)
(MT?.mroot mtv)
(MT?.hash_spec mtv)
(MT?.hash_fun mtv);
let hh2 = HST.get () in
RV.rv_inv_preserved
(MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.rv_inv_preserved
(MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved
(MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved
(MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2;
mt_safe_elts_preserved
0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt)
hh1 hh2
#pop-options
// `mt_create` initiates a Merkle tree with a given initial hash `init`.
// A valid Merkle tree should contain at least one element.
val mt_create_custom:
hsz:hash_size_t ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) ->
r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p
(requires (fun h0 ->
Rgl?.r_inv (hreg hsz) h0 init /\
HH.disjoint r (B.frameOf init)))
(ensures (fun h0 mt h1 ->
// memory safety
modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\
mt_safe h1 mt /\
// correctness
MT?.hash_size (B.get h1 mt 0) = hsz /\
mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init)))
#push-options "--z3rlimit 40"
let mt_create_custom hsz hash_spec r init hash_fun =
let hh0 = HST.get () in
let mt = create_empty_mt hsz hash_spec hash_fun r in
mt_insert hsz mt init;
let hh2 = HST.get () in
mt
#pop-options
/// Construction and Destruction of paths
// Since each element pointer in `path` is from the target Merkle tree and
// each element has different location in `MT?.hs` (thus different region id),
// we cannot use the regionality property for `path`s. Hence here we manually
// define invariants and representation.
noeq type path =
| Path: hash_size:hash_size_t ->
hashes:V.vector (hash #hash_size) ->
path
type path_p = B.pointer path
type const_path_p = const_pointer path
private
let phashes (h:HS.mem) (p:path_p)
: GTot (V.vector (hash #(Path?.hash_size (B.get h p 0))))
= Path?.hashes (B.get h p 0)
// Memory safety of a path as an invariant
inline_for_extraction noextract
val path_safe:
h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0
let path_safe h mtr p =
B.live h p /\ B.freeable p /\
V.live h (phashes h p) /\ V.freeable (phashes h p) /\
HST.is_eternal_region (V.frameOf (phashes h p)) /\
(let hsz = Path?.hash_size (B.get h p 0) in
V.forall_all h (phashes h p)
(fun hp -> Rgl?.r_inv (hreg hsz) h hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\
HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\
HH.disjoint mtr (B.frameOf p))
val path_loc: path_p -> GTot loc
let path_loc p = B.loc_all_regions_from false (B.frameOf p)
val lift_path_:
#hsz:hash_size_t ->
h:HS.mem ->
hs:S.seq (hash #hsz) ->
i:nat ->
j:nat{
i <= j /\ j <= S.length hs /\
V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} ->
GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j)
let rec lift_path_ #hsz h hs i j =
if i = j then S.empty
else (S.snoc (lift_path_ h hs i (j - 1))
(Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1))))
// Representation of a path
val lift_path:
#hsz:hash_size_t ->
h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} ->
GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))})
let lift_path #hsz h mtr p =
lift_path_ h (V.as_seq h (phashes h p))
0 (S.length (V.as_seq h (phashes h p)))
val lift_path_index_:
#hsz:hash_size_t ->
h:HS.mem ->
hs:S.seq (hash #hsz) ->
i:nat -> j:nat{i <= j && j <= S.length hs} ->
k:nat{i <= k && k < j} ->
Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)))
(ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) ==
S.index (lift_path_ h hs i j) (k - i)))
(decreases j)
[SMTPat (S.index (lift_path_ h hs i j) (k - i))]
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lift_path_index_ #hsz h hs i j k =
if i = j then ()
else if k = j - 1 then ()
else lift_path_index_ #hsz h hs i (j - 1) k
#pop-options
val lift_path_index:
h:HS.mem -> mtr:HH.rid ->
p:path_p -> i:uint32_t ->
Lemma (requires (path_safe h mtr p /\
i < V.size_of (phashes h p)))
(ensures (let hsz = Path?.hash_size (B.get h p 0) in
Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) ==
S.index (lift_path #(hsz) h mtr p) (U32.v i)))
let lift_path_index h mtr p i =
lift_path_index_ h (V.as_seq h (phashes h p))
0 (S.length (V.as_seq h (phashes h p))) (U32.v i)
val lift_path_eq:
#hsz:hash_size_t ->
h:HS.mem ->
hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) ->
i:nat -> j:nat ->
Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\
S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\
V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\
V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)))
(ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j)))
let lift_path_eq #hsz h hs1 hs2 i j =
assert (forall (k:nat{i <= k && k < j}).
S.index (lift_path_ h hs1 i j) (k - i) ==
Rgl?.r_repr (hreg hsz) h (S.index hs1 k));
assert (forall (k:nat{i <= k && k < j}).
S.index (lift_path_ h hs2 i j) (k - i) ==
Rgl?.r_repr (hreg hsz) h (S.index hs2 k));
assert (forall (k:nat{k < j - i}).
S.index (lift_path_ h hs1 i j) k ==
Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i)));
assert (forall (k:nat{k < j - i}).
S.index (lift_path_ h hs2 i j) k ==
Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i)));
assert (forall (k:nat{k < j - i}).
S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k);
assert (forall (k:nat{i <= k && k < j}).
S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i))
private
val path_safe_preserved_:
#hsz:hash_size_t ->
mtr:HH.rid -> hs:S.seq (hash #hsz) ->
i:nat -> j:nat{i <= j && j <= S.length hs} ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma
(requires (V.forall_seq hs i j
(fun hp ->
Rgl?.r_inv (hreg hsz) h0 hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (V.forall_seq hs i j
(fun hp ->
Rgl?.r_inv (hreg hsz) h1 hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp))))
(decreases j)
let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 =
if i = j then ()
else (assert (loc_includes
(B.loc_all_regions_from false mtr)
(B.loc_all_regions_from false
(Rgl?.region_of (hreg hsz) (S.index hs (j - 1)))));
Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1;
path_safe_preserved_ mtr hs i (j - 1) dl h0 h1)
val path_safe_preserved:
mtr:HH.rid -> p:path_p ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (path_safe h0 mtr p /\
loc_disjoint dl (path_loc p) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (path_safe h1 mtr p))
let path_safe_preserved mtr p dl h0 h1 =
assert (loc_includes (path_loc p) (B.loc_buffer p));
assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p)));
path_safe_preserved_
mtr (V.as_seq h0 (phashes h0 p))
0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1
val path_safe_init_preserved:
mtr:HH.rid -> p:path_p ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (path_safe h0 mtr p /\
V.size_of (phashes h0 p) = 0ul /\
B.loc_disjoint dl (path_loc p) /\
modifies dl h0 h1))
(ensures (path_safe h1 mtr p /\
V.size_of (phashes h1 p) = 0ul))
let path_safe_init_preserved mtr p dl h0 h1 =
assert (loc_includes (path_loc p) (B.loc_buffer p));
assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p)))
val path_preserved_:
#hsz:hash_size_t ->
mtr:HH.rid ->
hs:S.seq (hash #hsz) ->
i:nat -> j:nat{i <= j && j <= S.length hs} ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (V.forall_seq hs i j
(fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (path_safe_preserved_ mtr hs i j dl h0 h1;
S.equal (lift_path_ h0 hs i j)
(lift_path_ h1 hs i j)))
(decreases j)
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec path_preserved_ #hsz mtr hs i j dl h0 h1 =
if i = j then ()
else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1;
path_preserved_ mtr hs i (j - 1) dl h0 h1;
assert (loc_includes
(B.loc_all_regions_from false mtr)
(B.loc_all_regions_from false
(Rgl?.region_of (hreg hsz) (S.index hs (j - 1)))));
Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1)
#pop-options
val path_preserved:
mtr:HH.rid -> p:path_p ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (path_safe h0 mtr p /\
loc_disjoint dl (path_loc p) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (path_safe_preserved mtr p dl h0 h1;
let hsz0 = (Path?.hash_size (B.get h0 p 0)) in
let hsz1 = (Path?.hash_size (B.get h1 p 0)) in
let b:MTH.path = lift_path #hsz0 h0 mtr p in
let a:MTH.path = lift_path #hsz1 h1 mtr p in
hsz0 = hsz1 /\ S.equal b a))
let path_preserved mtr p dl h0 h1 =
assert (loc_includes (path_loc p) (B.loc_buffer p));
assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p)));
path_preserved_ mtr (V.as_seq h0 (phashes h0 p))
0 (S.length (V.as_seq h0 (phashes h0 p)))
dl h0 h1
val init_path:
hsz:hash_size_t ->
mtr:HH.rid -> r:HST.erid ->
HST.ST path_p
(requires (fun h0 -> HH.disjoint mtr r))
(ensures (fun h0 p h1 ->
// memory safety
path_safe h1 mtr p /\
// correctness
Path?.hash_size (B.get h1 p 0) = hsz /\
S.equal (lift_path #hsz h1 mtr p) S.empty))
let init_path hsz mtr r =
let nrid = HST.new_region r in
(B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul)
val clear_path:
mtr:HH.rid -> p:path_p ->
HST.ST unit
(requires (fun h0 -> path_safe h0 mtr p))
(ensures (fun h0 _ h1 ->
// memory safety
path_safe h1 mtr p /\
// correctness
V.size_of (phashes h1 p) = 0ul /\
S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty))
let clear_path mtr p =
let pv = !*p in
p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv))
val free_path:
p:path_p ->
HST.ST unit
(requires (fun h0 ->
B.live h0 p /\ B.freeable p /\
V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\
HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p)))
(ensures (fun h0 _ h1 ->
modifies (path_loc p) h0 h1))
let free_path p =
let pv = !*p in
V.free (Path?.hashes pv);
B.free p
/// Getting the Merkle root and path
// Construct "rightmost hashes" for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
private
val construct_rhs:
#hsz:hash_size_t ->
#hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} ->
acc:hash #hsz ->
actd:bool ->
hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\
HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\
Rgl?.r_inv (hreg hsz) h0 acc /\
HH.disjoint (B.frameOf acc) (V.frameOf hs) /\
HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\
mt_safe_elts #hsz h0 lv hs i j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf acc)))
h0 h1 /\
RV.rv_inv h1 rhs /\
Rgl?.r_inv (hreg hsz) h1 acc /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs i j;
MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec)
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) h0 hs)
(Rgl?.r_repr (hvreg hsz) h0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) h0 acc) actd ==
(Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc)
)))
(decreases (U32.v j))
#push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun =
let hh0 = HST.get () in
if j = 0ul then begin
assert (RV.rv_inv hh0 hs);
assert (mt_safe_elts #hsz hh0 lv hs i j);
mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul;
assert (MTH.hs_wf_elts #(U32.v hsz)
(U32.v lv) (RV.as_seq hh0 hs)
(U32.v i) (U32.v j));
let hh1 = HST.get() in
assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec)
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 acc) actd ==
(Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc))
end
else
let ofs = offset_of i in
begin
(if j % 2ul = 0ul
then begin
Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1);
mt_safe_elts_rec #hsz hh0 lv hs i j;
construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun;
let hh1 = HST.get () in
// correctness
mt_safe_elts_spec #hsz hh0 lv hs i j;
MTH.construct_rhs_even #(U32.v hsz) #hash_spec
(U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd;
assert (MTH.construct_rhs #(U32.v hsz) #hash_spec
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 acc)
actd ==
(Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc))
end
else begin
if actd
then begin
RV.assign_copy (hcpy hsz) rhs lv acc;
let hh1 = HST.get () in
// memory safety
Rgl?.r_sep (hreg hsz) acc
(B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1;
RV.rv_inv_preserved
hs (B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
RV.as_seq_preserved
hs (B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
RV.rv_inv_preserved
(V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
V.loc_vector_within_included hs lv (V.size_of hs);
mt_safe_elts_preserved lv hs i j
(B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
mt_safe_elts_head hh1 lv hs i j;
hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs);
// correctness
assert (S.equal (RV.as_seq hh1 rhs)
(S.upd (RV.as_seq hh0 rhs) (U32.v lv)
(Rgl?.r_repr (hreg hsz) hh0 acc)));
hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc;
let hh2 = HST.get () in
// memory safety
mt_safe_elts_preserved lv hs i j
(B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2;
RV.rv_inv_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.rv_inv_preserved
rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.as_seq_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.as_seq_preserved
rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
// correctness
hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs);
assert (Rgl?.r_repr (hreg hsz) hh2 acc ==
(Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs))
(Rgl?.r_repr (hreg hsz) hh0 acc))
end
else begin
mt_safe_elts_head hh0 lv hs i j;
hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs);
hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc);
Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc;
let hh1 = HST.get () in
// memory safety
V.loc_vector_within_included hs lv (V.size_of hs);
mt_safe_elts_preserved lv hs i j
(B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.rv_inv_preserved
hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.rv_inv_preserved
rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.as_seq_preserved
hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.as_seq_preserved
rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
// correctness
hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs);
assert (Rgl?.r_repr (hreg hsz) hh1 acc ==
S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs))
end;
let hh3 = HST.get () in
assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs));
assert (S.equal (RV.as_seq hh3 rhs)
(if actd
then S.upd (RV.as_seq hh0 rhs) (U32.v lv)
(Rgl?.r_repr (hreg hsz) hh0 acc)
else RV.as_seq hh0 rhs));
assert (Rgl?.r_repr (hreg hsz) hh3 acc ==
(if actd
then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs))
(Rgl?.r_repr (hreg hsz) hh0 acc)
else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs)));
mt_safe_elts_rec hh3 lv hs i j;
construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun;
let hh4 = HST.get () in
mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul);
assert (MTH.construct_rhs #(U32.v hsz) #hash_spec
(U32.v lv + 1)
(Rgl?.r_repr (hvvreg hsz) hh3 hs)
(Rgl?.r_repr (hvreg hsz) hh3 rhs)
(U32.v i / 2) (U32.v j / 2)
(Rgl?.r_repr (hreg hsz) hh3 acc) true ==
(Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc));
mt_safe_elts_spec hh0 lv hs i j;
MTH.construct_rhs_odd #(U32.v hsz) #hash_spec
(U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd;
assert (MTH.construct_rhs #(U32.v hsz) #hash_spec
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 acc) actd ==
(Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc))
end)
end
#pop-options
private inline_for_extraction
val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool
let mt_get_root_pre_nst mtv rt = true
val mt_get_root_pre:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
rt:hash #hsz ->
HST.ST bool
(requires (fun h0 ->
let mt = CB.cast mt in
MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\
mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\
HH.disjoint (B.frameOf mt) (B.frameOf rt)))
(ensures (fun _ _ _ -> True))
let mt_get_root_pre #hsz mt rt =
let mt = CB.cast mt in
let mt = !*mt in
let hsz = MT?.hash_size mt in
assert (MT?.hash_size mt = hsz);
mt_get_root_pre_nst mt rt
// `mt_get_root` returns the Merkle root. If it's already calculated with
// up-to-date hashes, the root is returned immediately. Otherwise it calls
// `construct_rhs` to build rightmost hashes and to calculate the Merkle root
// as well.
val mt_get_root:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
rt:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
let mt = CB.cast mt in
let dmt = B.get h0 mt 0 in
MT?.hash_size dmt = (Ghost.reveal hsz) /\
mt_get_root_pre_nst dmt rt /\
mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\
HH.disjoint (B.frameOf mt) (B.frameOf rt)))
(ensures (fun h0 _ h1 ->
let mt = CB.cast mt in
// memory safety
modifies (loc_union
(mt_loc mt)
(B.loc_all_regions_from false (B.frameOf rt)))
h0 h1 /\
mt_safe h1 mt /\
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
MT?.hash_size mtv0 = (Ghost.reveal hsz) /\
MT?.hash_size mtv1 = (Ghost.reveal hsz) /\
MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\
MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\
MT?.offset mtv1 == MT?.offset mtv0 /\
MT?.rhs_ok mtv1 = true /\
Rgl?.r_inv (hreg hsz) h1 rt /\
// correctness
MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) ==
(mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt))))
#push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1"
let mt_get_root #hsz mt rt =
let mt = CB.cast mt in
let hh0 = HST.get () in
let mtv = !*mt in
let prefix = MT?.offset mtv in
let i = MT?.i mtv in
let j = MT?.j mtv in
let hs = MT?.hs mtv in
let rhs = MT?.rhs mtv in
let mroot = MT?.mroot mtv in
let hash_size = MT?.hash_size mtv in
let hash_spec = MT?.hash_spec mtv in
let hash_fun = MT?.hash_fun mtv in
if MT?.rhs_ok mtv
then begin
Cpy?.copy (hcpy hash_size) hash_size mroot rt;
let hh1 = HST.get () in
mt_safe_preserved mt
(B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1;
mt_preserved mt
(B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1;
MTH.mt_get_root_rhs_ok_true
(mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt);
assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) ==
(mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt))
end
else begin
construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun;
let hh1 = HST.get () in
// memory safety
assert (RV.rv_inv hh1 rhs);
assert (Rgl?.r_inv (hreg hsz) hh1 rt);
assert (B.live hh1 mt);
RV.rv_inv_preserved
hs (loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf rt)))
hh0 hh1;
RV.as_seq_preserved
hs (loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf rt)))
hh0 hh1;
V.loc_vector_within_included hs 0ul (V.size_of hs);
mt_safe_elts_preserved 0ul hs i j
(loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf rt)))
hh0 hh1;
// correctness
mt_safe_elts_spec hh0 0ul hs i j;
assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 rt) false ==
(Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt));
Cpy?.copy (hcpy hash_size) hash_size rt mroot;
let hh2 = HST.get () in
// memory safety
RV.rv_inv_preserved
hs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
RV.rv_inv_preserved
rhs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
RV.as_seq_preserved
hs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
RV.as_seq_preserved
rhs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
B.modifies_buffer_elim
rt (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
mt_safe_elts_preserved 0ul hs i j
(B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
// correctness
assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt);
mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun;
let hh3 = HST.get () in
// memory safety
Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3;
RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3;
RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3;
RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3;
RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3;
Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3;
mt_safe_elts_preserved 0ul hs i j
(B.loc_buffer mt) hh2 hh3;
assert (mt_safe hh3 mt);
// correctness
MTH.mt_get_root_rhs_ok_false
(mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt);
assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) ==
(MTH.MT #(U32.v hash_size)
(U32.v i) (U32.v j)
(RV.as_seq hh0 hs)
true
(RV.as_seq hh1 rhs)
(Rgl?.r_repr (hreg hsz) hh1 rt)
hash_spec,
Rgl?.r_repr (hreg hsz) hh1 rt));
assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) ==
(mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt))
end
#pop-options
inline_for_extraction
val mt_path_insert:
#hsz:hash_size_t ->
mtr:HH.rid -> p:path_p -> hp:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
path_safe h0 mtr p /\
not (V.is_full (phashes h0 p)) /\
Rgl?.r_inv (hreg hsz) h0 hp /\
HH.disjoint mtr (B.frameOf p) /\
HH.includes mtr (B.frameOf hp) /\
Path?.hash_size (B.get h0 p 0) = hsz))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (path_loc p) h0 h1 /\
path_safe h1 mtr p /\
// correctness
(let hsz0 = Path?.hash_size (B.get h0 p 0) in
let hsz1 = Path?.hash_size (B.get h1 p 0) in
(let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in
let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in
V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\
hsz = hsz0 /\ hsz = hsz1 /\
(let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in
S.equal hspec after)))))
#push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1"
let mt_path_insert #hsz mtr p hp =
let pth = !*p in
let pv = Path?.hashes pth in
let hh0 = HST.get () in
let ipv = V.insert pv hp in
let hh1 = HST.get () in
path_safe_preserved_
mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv))
(B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1;
path_preserved_
mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv))
(B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1;
Rgl?.r_sep (hreg hsz) hp
(B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1;
p *= Path hsz ipv;
let hh2 = HST.get () in
path_safe_preserved_
mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv))
(B.loc_region_only false (B.frameOf p)) hh1 hh2;
path_preserved_
mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv))
(B.loc_region_only false (B.frameOf p)) hh1 hh2;
Rgl?.r_sep (hreg hsz) hp
(B.loc_region_only false (B.frameOf p)) hh1 hh2;
assert (S.equal (lift_path hh2 mtr p)
(lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp)
0 (S.length (V.as_seq hh1 ipv))));
lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv)
0 (S.length (V.as_seq hh0 pv))
#pop-options
// For given a target index `k`, the number of elements (in the tree) `j`,
// and a boolean flag (to check the existence of rightmost hashes), we can
// calculate a required Merkle path length.
//
// `mt_path_length` is a postcondition of `mt_get_path`, and a precondition
// of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`.
private
val mt_path_length_step:
k:index_t ->
j:index_t{k <= j} ->
actd:bool ->
Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd})
let mt_path_length_step k j actd =
if j = 0ul then 0ul
else (if k % 2ul = 0ul
then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul)
else 1ul)
private inline_for_extraction
val mt_path_length:
lv:uint32_t{lv <= merkle_tree_size_lg} ->
k:index_t ->
j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} ->
actd:bool ->
Tot (l:uint32_t{
U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd &&
l <= 32ul - lv})
(decreases (U32.v j))
#push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1"
let rec mt_path_length lv k j actd =
if j = 0ul then 0ul
else (let nactd = actd || (j % 2ul = 1ul) in
mt_path_length_step k j actd +
mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd)
#pop-options
val mt_get_path_length:
mtr:HH.rid ->
p:const_path_p ->
HST.ST uint32_t
(requires (fun h0 -> path_safe h0 mtr (CB.cast p)))
(ensures (fun h0 _ h1 -> True))
let mt_get_path_length mtr p =
let pd = !*(CB.cast p) in
V.size_of (Path?.hashes pd)
private inline_for_extraction
val mt_make_path_step:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
mtr:HH.rid ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} ->
k:index_t{i <= k && k <= j} ->
p:path_p ->
actd:bool ->
HST.ST unit
(requires (fun h0 ->
HH.includes mtr (V.frameOf hs) /\
HH.includes mtr (V.frameOf rhs) /\
RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\
mt_safe_elts h0 lv hs i j /\
path_safe h0 mtr p /\
Path?.hash_size (B.get h0 p 0) = hsz /\
V.size_of (phashes h0 p) <= lv + 1ul))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (path_loc p) h0 h1 /\
path_safe h1 mtr p /\
V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\
V.size_of (phashes h1 p) <= lv + 2ul /\
// correctness
(mt_safe_elts_spec h0 lv hs i j;
(let hsz0 = Path?.hash_size (B.get h0 p 0) in
let hsz1 = Path?.hash_size (B.get h1 p 0) in
let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in
let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in
hsz = hsz0 /\ hsz = hsz1 /\
S.equal after
(MTH.mt_make_path_step
(U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs)
(U32.v i) (U32.v j) (U32.v k) before actd)))))
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let mt_make_path_step #hsz lv mtr hs rhs i j k p actd =
let pth = !*p in
let hh0 = HST.get () in
let ofs = offset_of i in
if k % 2ul = 1ul
then begin
hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs);
assert (HH.includes mtr
(B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs))));
assert(Path?.hash_size pth = hsz);
mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs))
end
else begin
if k = j then ()
else if k + 1ul = j
then (if actd
then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv)));
mt_path_insert mtr p (V.index rhs lv)))
else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs);
assert (HH.includes mtr
(B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs))));
mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs)))
end
#pop-options
private inline_for_extraction
val mt_get_path_step_pre_nst:
#hsz:Ghost.erased hash_size_t ->
mtr:HH.rid ->
p:path ->
i:uint32_t ->
Tot bool
let mt_get_path_step_pre_nst #hsz mtr p i =
i < V.size_of (Path?.hashes p)
val mt_get_path_step_pre:
#hsz:Ghost.erased hash_size_t ->
mtr:HH.rid ->
p:const_path_p ->
i:uint32_t ->
HST.ST bool
(requires (fun h0 ->
path_safe h0 mtr (CB.cast p) /\
(let pv = B.get h0 (CB.cast p) 0 in
Path?.hash_size pv = Ghost.reveal hsz /\
live h0 (Path?.hashes pv) /\
mt_get_path_step_pre_nst #hsz mtr pv i)))
(ensures (fun _ _ _ -> True))
let mt_get_path_step_pre #hsz mtr p i =
let p = CB.cast p in
mt_get_path_step_pre_nst #hsz mtr !*p i
val mt_get_path_step:
#hsz:Ghost.erased hash_size_t ->
mtr:HH.rid ->
p:const_path_p ->
i:uint32_t ->
HST.ST (hash #hsz)
(requires (fun h0 ->
path_safe h0 mtr (CB.cast p) /\
(let pv = B.get h0 (CB.cast p) 0 in
Path?.hash_size pv = Ghost.reveal hsz /\
live h0 (Path?.hashes pv) /\
i < V.size_of (Path?.hashes pv))))
(ensures (fun h0 r h1 -> True ))
let mt_get_path_step #hsz mtr p i =
let pd = !*(CB.cast p) in
V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i
private
val mt_get_path_:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
mtr:HH.rid ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} ->
k:index_t{i <= k && k <= j} ->
p:path_p ->
actd:bool ->
HST.ST unit
(requires (fun h0 ->
HH.includes mtr (V.frameOf hs) /\
HH.includes mtr (V.frameOf rhs) /\
RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\
mt_safe_elts h0 lv hs i j /\
path_safe h0 mtr p /\
Path?.hash_size (B.get h0 p 0) = hsz /\
V.size_of (phashes h0 p) <= lv + 1ul))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (path_loc p) h0 h1 /\
path_safe h1 mtr p /\
V.size_of (phashes h1 p) ==
V.size_of (phashes h0 p) + mt_path_length lv k j actd /\
// correctness
(mt_safe_elts_spec h0 lv hs i j;
(let hsz0 = Path?.hash_size (B.get h0 p 0) in
let hsz1 = Path?.hash_size (B.get h1 p 0) in
let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in
let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in
hsz = hsz0 /\ hsz = hsz1 /\
S.equal after
(MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs)
(U32.v i) (U32.v j) (U32.v k) before actd)))))
(decreases (32 - U32.v lv))
#push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2"
let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd =
let hh0 = HST.get () in
mt_safe_elts_spec hh0 lv hs i j;
let ofs = offset_of i in
if j = 0ul then ()
else
(mt_make_path_step lv mtr hs rhs i j k p actd;
let hh1 = HST.get () in
mt_safe_elts_spec hh0 lv hs i j;
assert (S.equal (lift_path hh1 mtr p)
(MTH.mt_make_path_step
(U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs)
(U32.v i) (U32.v j) (U32.v k)
(lift_path hh0 mtr p) actd));
RV.rv_inv_preserved hs (path_loc p) hh0 hh1;
RV.rv_inv_preserved rhs (path_loc p) hh0 hh1;
RV.as_seq_preserved hs (path_loc p) hh0 hh1;
RV.as_seq_preserved rhs (path_loc p) hh0 hh1;
V.loc_vector_within_included hs lv (V.size_of hs);
mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1;
assert (mt_safe_elts hh1 lv hs i j);
mt_safe_elts_rec hh1 lv hs i j;
mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul);
mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p
(if j % 2ul = 0ul then actd else true);
let hh2 = HST.get () in
assert (S.equal (lift_path hh2 mtr p)
(MTH.mt_get_path_ (U32.v lv + 1)
(RV.as_seq hh1 hs) (RV.as_seq hh1 rhs)
(U32.v i / 2) (U32.v j / 2) (U32.v k / 2)
(lift_path hh1 mtr p)
(if U32.v j % 2 = 0 then actd else true)));
assert (S.equal (lift_path hh2 mtr p)
(MTH.mt_get_path_ (U32.v lv)
(RV.as_seq hh0 hs) (RV.as_seq hh0 rhs)
(U32.v i) (U32.v j) (U32.v k)
(lift_path hh0 mtr p) actd)))
#pop-options
private inline_for_extraction
val mt_get_path_pre_nst:
mtv:merkle_tree ->
idx:offset_t ->
p:path ->
root:(hash #(MT?.hash_size mtv)) ->
Tot bool
let mt_get_path_pre_nst mtv idx p root =
offsets_connect (MT?.offset mtv) idx &&
Path?.hash_size p = MT?.hash_size mtv &&
([@inline_let] let idx = split_offset (MT?.offset mtv) idx in
MT?.i mtv <= idx && idx < MT?.j mtv &&
V.size_of (Path?.hashes p) = 0ul)
val mt_get_path_pre:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
idx:offset_t ->
p:const_path_p ->
root:hash #hsz ->
HST.ST bool
(requires (fun h0 ->
let mt = CB.cast mt in
let p = CB.cast p in
let dmt = B.get h0 mt 0 in
let dp = B.get h0 p 0 in
MT?.hash_size dmt = (Ghost.reveal hsz) /\
Path?.hash_size dp = (Ghost.reveal hsz) /\
mt_safe h0 mt /\
path_safe h0 (B.frameOf mt) p /\
Rgl?.r_inv (hreg hsz) h0 root /\
HH.disjoint (B.frameOf root) (B.frameOf mt) /\
HH.disjoint (B.frameOf root) (B.frameOf p)))
(ensures (fun _ _ _ -> True))
let mt_get_path_pre #_ mt idx p root =
let mt = CB.cast mt in
let p = CB.cast p in
let mtv = !*mt in
mt_get_path_pre_nst mtv idx !*p root
val mt_get_path_loc_union_helper:
l1:loc -> l2:loc ->
Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2)
let mt_get_path_loc_union_helper l1 l2 = ()
// Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost
// hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree
// to the output path.
#push-options "--z3rlimit 60"
val mt_get_path:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
idx:offset_t ->
p:path_p ->
root:hash #hsz ->
HST.ST index_t
(requires (fun h0 ->
let mt = CB.cast mt in
let dmt = B.get h0 mt 0 in
MT?.hash_size dmt = Ghost.reveal hsz /\
Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\
mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\
mt_safe h0 mt /\
path_safe h0 (B.frameOf mt) p /\
Rgl?.r_inv (hreg hsz) h0 root /\
HH.disjoint (B.frameOf root) (B.frameOf mt) /\
HH.disjoint (B.frameOf root) (B.frameOf p)))
(ensures (fun h0 _ h1 ->
let mt = CB.cast mt in
let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let idx = split_offset (MT?.offset mtv0) idx in
MT?.hash_size mtv0 = Ghost.reveal hsz /\
MT?.hash_size mtv1 = Ghost.reveal hsz /\
Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\
Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\
// memory safety
modifies (loc_union
(loc_union
(mt_loc mt)
(B.loc_all_regions_from false (B.frameOf root)))
(path_loc p))
h0 h1 /\
mt_safe h1 mt /\
path_safe h1 (B.frameOf mt) p /\
Rgl?.r_inv (hreg hsz) h1 root /\
V.size_of (phashes h1 p) ==
1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\
// correctness
(let sj, sp, srt =
MTH.mt_get_path
(mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in
sj == U32.v (MT?.j mtv1) /\
S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\
srt == Rgl?.r_repr (hreg hsz) h1 root)))
#pop-options
#push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1"
let mt_get_path #hsz mt idx p root =
let ncmt = CB.cast mt in
let mtframe = B.frameOf ncmt in
let hh0 = HST.get () in
mt_get_root mt root;
let mtv = !*ncmt in
let hsz = MT?.hash_size mtv in
let hh1 = HST.get () in
path_safe_init_preserved mtframe p
(B.loc_union (mt_loc ncmt)
(B.loc_all_regions_from false (B.frameOf root)))
hh0 hh1;
assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) ==
(mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root));
assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty);
let idx = split_offset (MT?.offset mtv) idx in
let i = MT?.i mtv in
let ofs = offset_of (MT?.i mtv) in
let j = MT?.j mtv in
let hs = MT?.hs mtv in
let rhs = MT?.rhs mtv in
assert (mt_safe_elts hh1 0ul hs i j);
assert (V.size_of (V.get hh1 hs 0ul) == j - ofs);
assert (idx < j);
hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs);
hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs);
hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs);
let ih = V.index (V.index hs 0ul) (idx - ofs) in
mt_path_insert #hsz mtframe p ih;
let hh2 = HST.get () in
assert (S.equal (lift_path hh2 mtframe p)
(MTH.path_insert
(lift_path hh1 mtframe p)
(S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs))));
Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2;
mt_safe_preserved ncmt (path_loc p) hh1 hh2;
mt_preserved ncmt (path_loc p) hh1 hh2;
assert (V.size_of (phashes hh2 p) == 1ul);
mt_get_path_ 0ul mtframe hs rhs i j idx p false;
let hh3 = HST.get () in
// memory safety
mt_get_path_loc_union_helper
(loc_union (mt_loc ncmt)
(B.loc_all_regions_from false (B.frameOf root)))
(path_loc p);
Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3;
mt_safe_preserved ncmt (path_loc p) hh2 hh3;
mt_preserved ncmt (path_loc p) hh2 hh3;
assert (V.size_of (phashes hh3 p) ==
1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false);
assert (S.length (lift_path #hsz hh3 mtframe p) ==
S.length (lift_path #hsz hh2 mtframe p) +
MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false);
assert (modifies (loc_union
(loc_union
(mt_loc ncmt)
(B.loc_all_regions_from false (B.frameOf root)))
(path_loc p))
hh0 hh3);
assert (mt_safe hh3 ncmt);
assert (path_safe hh3 mtframe p);
assert (Rgl?.r_inv (hreg hsz) hh3 root);
assert (V.size_of (phashes hh3 p) ==
1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false);
// correctness
mt_safe_elts_spec hh2 0ul hs i j;
assert (S.equal (lift_path hh3 mtframe p)
(MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs)
(U32.v i) (U32.v j) (U32.v idx)
(lift_path hh2 mtframe p) false));
assert (MTH.mt_get_path
(mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) ==
(U32.v (MT?.j (B.get hh3 ncmt 0)),
lift_path hh3 mtframe p,
Rgl?.r_repr (hreg hsz) hh3 root));
j
#pop-options
/// Flushing
private val
mt_flush_to_modifies_rec_helper:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
h:HS.mem ->
Lemma (loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) ==
loc_union
(RV.rv_loc_elems h hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
#push-options "--initial_fuel 2 --max_fuel 2"
let mt_flush_to_modifies_rec_helper #hsz lv hs h =
assert (V.loc_vector_within hs lv (V.size_of hs) ==
loc_union (V.loc_vector_within hs lv (lv + 1ul))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)));
RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs));
assert (RV.rv_loc_elems h hs lv (V.size_of hs) ==
loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)));
loc_union_assoc_4
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
#pop-options
private
val mt_flush_to_:
hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
pi:index_t ->
i:index_t{i >= pi} ->
j:Ghost.erased index_t{
Ghost.reveal j >= i &&
U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
mt_safe_elts h0 lv hs pi (Ghost.reveal j)))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rv_loc_elems h0 hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
h0 h1 /\
RV.rv_inv h1 hs /\
mt_safe_elts h1 lv hs i (Ghost.reveal j) /\
// correctness
(mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j);
S.equal (RV.as_seq h1 hs)
(MTH.mt_flush_to_
(U32.v lv) (RV.as_seq h0 hs) (U32.v pi)
(U32.v i) (U32.v (Ghost.reveal j))))))
(decreases (U32.v i))
#restart-solver
#push-options "--z3rlimit 1500 --fuel 1 --ifuel 0"
let rec mt_flush_to_ hsz lv hs pi i j =
let hh0 = HST.get () in
// Base conditions
mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j);
V.loc_vector_within_included hs 0ul lv;
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j)
else begin
/// 1) Flush hashes at the level `lv`, where the new vector is
/// not yet connected to `hs`.
let ofs = oi - opi in
let hvec = V.index hs lv in
let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in
let hh1 = HST.get () in
// 1-0) Basic disjointness conditions for `RV.assign`
V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall_preserved
hs 0ul lv
(fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec)
(Rgl?.region_of (hvreg hsz) b))
(RV.loc_rvector hvec)
hh0 hh1;
V.forall_preserved
hs (lv + 1ul) (V.size_of hs)
(fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec)
(Rgl?.region_of (hvreg hsz) b))
(RV.loc_rvector hvec)
hh0 hh1;
assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed);
// 1-1) For the `modifies` postcondition.
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
// 1-2) Preservation
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-3) For `mt_safe_elts`
assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated
mt_safe_elts_preserved
(lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet
// 1-4) For the `rv_inv` postcondition
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v lv);
RV.rv_elems_inv_preserved
hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs))
(U32.v lv + 1) (U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
(U32.v lv + 1) (U32.v (V.size_of hs));
RV.rv_elems_inv_preserved
hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
assert (rv_itself_inv hh1 hs);
assert (elems_reg hh1 hs);
// 1-5) Correctness
assert (S.equal (RV.as_seq hh1 flushed)
(S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs)
(S.length (RV.as_seq hh0 (V.get hh0 hs lv)))));
/// 2) Assign the flushed vector to `hs` at the level `lv`.
RV.assign hs lv flushed;
let hh2 = HST.get () in
// 2-1) For the `modifies` postcondition.
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2);
// 2-2) Preservation
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-3) For `mt_safe_elts`
assert (V.size_of (V.get hh2 hs lv) ==
Ghost.reveal j - offset_of i);
mt_safe_elts_preserved
(lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-4) Correctness
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append
(RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 flushed)
(RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed);
// if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`,
// contradicting the branch.
assert (lv + 1ul < merkle_tree_size_lg);
assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul)));
assert (RV.rv_inv hh2 hs);
assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul));
/// 3) Recursion
mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul)
(Ghost.hide (Ghost.reveal j / 2ul));
let hh3 = HST.get () in
// 3-0) Memory safety brought from the postcondition of the recursion
assert (modifies
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))))
hh0 hh3);
mt_flush_to_modifies_rec_helper lv hs hh0;
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
V.loc_vector_within_included hs lv (lv + 1ul);
RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs);
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)));
V.get_preserved hs lv
(loc_union
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
hh2 hh3;
assert (V.size_of (V.get hh3 hs lv) ==
Ghost.reveal j - offset_of i);
assert (RV.rv_inv hh3 hs);
mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j);
assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j));
// 3-1) Correctness
mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul);
assert (S.equal (RV.as_seq hh3 hs)
(MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs)
(U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2)));
mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j);
MTH.mt_flush_to_rec
(U32.v lv) (RV.as_seq hh0 hs)
(U32.v pi) (U32.v i) (U32.v (Ghost.reveal j));
assert (S.equal (RV.as_seq hh3 hs)
(MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs)
(U32.v pi) (U32.v i) (U32.v (Ghost.reveal j))))
end
#pop-options
// `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements
// from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure,
// i.e., the tree still holds some old internal hashes (compressed from old
// hashes) which are required to generate Merkle paths for remaining hashes.
//
// Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash
// elements. If there are `MT?.j` number of elements in the tree, because of the
// precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after
// flushing.
private inline_for_extraction
val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool
let mt_flush_to_pre_nst mtv idx =
offsets_connect (MT?.offset mtv) idx &&
([@inline_let] let idx = split_offset (MT?.offset mtv) idx in
idx >= MT?.i mtv &&
idx < MT?.j mtv)
val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool
(requires (fun h0 -> mt_safe h0 (CB.cast mt)))
(ensures (fun _ _ _ -> True))
let mt_flush_to_pre mt idx =
let mt = CB.cast mt in
let h0 = HST.get() in
let mtv = !*mt in
mt_flush_to_pre_nst mtv idx
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1"
val mt_flush_to:
mt:mt_p ->
idx:offset_t ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
// correctness
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let off = MT?.offset mtv0 in
let idx = split_offset off idx in
MT?.hash_size mtv0 = MT?.hash_size mtv1 /\
MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt)))
let mt_flush_to mt idx =
let hh0 = HST.get () in
let mtv = !*mt in
let offset = MT?.offset mtv in
let j = MT?.j mtv in
let hsz = MT?.hash_size mtv in
let idx = split_offset offset idx in
let hs = MT?.hs mtv in
mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv));
let hh1 = HST.get () in
RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs);
V.loc_vector_within_included hs 0ul (V.size_of hs);
RV.rv_inv_preserved
(MT?.rhs mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
RV.as_seq_preserved
(MT?.rhs mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
mt *= MT (MT?.hash_size mtv)
(MT?.offset mtv) idx (MT?.j mtv)
hs
(MT?.rhs_ok mtv) (MT?.rhs mtv)
(MT?.mroot mtv)
(MT?.hash_spec mtv) (MT?.hash_fun mtv);
let hh2 = HST.get () in
RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2;
mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2
#pop-options
private inline_for_extraction
val mt_flush_pre_nst: mt:merkle_tree -> Tot bool
let mt_flush_pre_nst mt = MT?.j mt > MT?.i mt
val mt_flush_pre: mt:const_mt_p -> HST.ST bool (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ _ -> True))
let mt_flush_pre mt = mt_flush_pre_nst !*(CB.cast mt)
val mt_flush:
mt:mt_p ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt /\ mt_flush_pre_nst (B.get h0 mt 0)))
(ensures (fun h0 _ h1 ->
let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
// memory safety
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
// correctness
MT?.hash_size mtv0 = MT?.hash_size mtv1 /\
MTH.mt_flush (mt_lift h0 mt) == mt_lift h1 mt))
#push-options "--z3rlimit 200 --initial_fuel 1 --max_fuel 1"
let mt_flush mt =
let mtv = !*mt in
let off = MT?.offset mtv in
let j = MT?.j mtv in
let j1 = j - 1ul in
assert (j1 < uint32_32_max);
assert (off < uint64_max);
assert (UInt.fits (U64.v off + U32.v j1) 64);
let jo = join_offset off j1 in
mt_flush_to mt jo
#pop-options
/// Retraction
private
val mt_retract_to_:
#hsz:hash_size_t ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
lv:uint32_t{lv < V.size_of hs} ->
i:index_t ->
s:index_t ->
j:index_t{i <= s && s <= j && v j < pow2 (U32.v (V.size_of hs) - v lv)}
-> HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
mt_safe_elts h0 lv hs i j))
(ensures (fun h0 _ h1 ->
// memory safety
(modifies (loc_union
(RV.rv_loc_elems h0 hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
h0 h1) /\
RV.rv_inv h1 hs /\
mt_safe_elts h1 lv hs i s /\
// correctness
(mt_safe_elts_spec h0 lv hs i j;
S.equal (RV.as_seq h1 hs)
(MTH.mt_retract_to_
(RV.as_seq h0 hs) (U32.v lv)
(U32.v i) (U32.v s) (U32.v j)))
))
(decreases (U32.v merkle_tree_size_lg - U32.v lv))
#push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1"
private
let rec mt_retract_to_ #hsz hs lv i s j =
let hh0 = HST.get () in
// Base conditions
mt_safe_elts_rec hh0 lv hs i j;
V.loc_vector_within_included hs 0ul lv;
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
if lv >= V.size_of hs then ()
else begin
// 1) Retract hashes at level `lv`.
let hvec = V.index hs lv in
let old_len = j - offset_of i in
let new_len = s - offset_of i in
let retracted = RV.shrink hvec new_len in
let hh1 = HST.get () in
// 1-0) Basic disjointness conditions for `RV.assign`
V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall_preserved
hs 0ul lv
(fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec)
(Rgl?.region_of (hvreg hsz) b))
(RV.loc_rvector hvec)
hh0 hh1;
V.forall_preserved
hs (lv + 1ul) (V.size_of hs)
(fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec)
(Rgl?.region_of (hvreg hsz) b))
(RV.loc_rvector hvec)
hh0 hh1;
assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) retracted);
// 1-1) For the `modifies` postcondition.
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
// 1-2) Preservation
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-3) For `mt_safe_elts`
assert (V.size_of retracted == new_len);
mt_safe_elts_preserved
(lv + 1ul) hs (i / 2ul) (j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-4) For the `rv_inv` postcondition
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v lv);
RV.rv_elems_inv_preserved
hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs))
(U32.v lv + 1) (U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
(U32.v lv + 1) (U32.v (V.size_of hs));
RV.rv_elems_inv_preserved
hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
assert (rv_itself_inv hh1 hs);
assert (elems_reg hh1 hs);
// 1-5) Correctness
assert (S.equal (RV.as_seq hh1 retracted)
(S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) 0 (U32.v new_len)));
RV.assign hs lv retracted;
let hh2 = HST.get() in
// 2-1) For the `modifies` postcondition.
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2);
// 2-2) Preservation
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-3) For `mt_safe_elts`
assert (V.size_of (V.get hh2 hs lv) == s - offset_of i);
mt_safe_elts_preserved
(lv + 1ul) hs (i / 2ul) (j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-4) Correctness
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector retracted) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector retracted) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append
(RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 retracted)
(RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 retracted);
if lv + 1ul < V.size_of hs then
begin
assert (mt_safe_elts hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul));
mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul);
mt_retract_to_ hs (lv + 1ul) (i / 2ul) (s / 2ul) (j / 2ul);
// 3-0) Memory safety brought from the postcondition of the recursion
let hh3 = HST.get () in
assert (modifies
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))))
hh0 hh3);
mt_flush_to_modifies_rec_helper lv hs hh0;
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
V.loc_vector_within_included hs lv (lv + 1ul);
RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs);
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)));
V.get_preserved hs lv
(loc_union
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
hh2 hh3;
assert (V.size_of (V.get hh3 hs lv) == s - offset_of i);
assert (RV.rv_inv hh3 hs);
mt_safe_elts_constr hh3 lv hs i s;
assert (mt_safe_elts hh3 lv hs i s);
// 3-1) Correctness
mt_safe_elts_spec hh2 (lv + 1ul) hs (i / 2ul) (j / 2ul);
assert (U32.v lv + 1 < S.length (RV.as_seq hh3 hs) ==>
S.equal (RV.as_seq hh3 hs)
(MTH.mt_retract_to_ (RV.as_seq hh2 hs) (U32.v lv + 1)
(U32.v i / 2) (U32.v s / 2) (U32.v j / 2)));
assert (RV.rv_inv hh0 hs);
assert (mt_safe_elts hh0 lv hs i j);
mt_safe_elts_spec hh0 lv hs i j;
assert (S.equal (RV.as_seq hh3 hs)
(MTH.mt_retract_to_ (RV.as_seq hh0 hs) (U32.v lv)
(U32.v i) (U32.v s) (U32.v j)))
end
else begin
let hh3 = HST.get() in
assert ((modifies (loc_union
(RV.rv_loc_elems hh0 hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
hh0 hh3));
assert (RV.rv_inv hh3 hs /\ mt_safe_elts hh3 lv hs i s);
mt_safe_elts_spec hh0 lv hs i j;
assert (S.equal (RV.as_seq hh3 hs)
(MTH.mt_retract_to_
(RV.as_seq hh0 hs) (U32.v lv)
(U32.v i) (U32.v s) (U32.v j)))
end
end
#pop-options
private inline_for_extraction
val mt_retract_to_pre_nst: mtv:merkle_tree -> r:offset_t -> Tot bool
let mt_retract_to_pre_nst mtv r =
offsets_connect (MT?.offset mtv) r &&
([@inline_let] let r = split_offset (MT?.offset mtv) r in
MT?.i mtv <= r && r < MT?.j mtv)
val mt_retract_to_pre: mt:const_mt_p -> r:offset_t -> HST.ST bool
(requires (fun h0 -> mt_safe h0 (CB.cast mt)))
(ensures (fun _ _ _ -> True))
let mt_retract_to_pre mt r =
let mt = CB.cast mt in
let h0 = HST.get() in
let mtv = !*mt in
mt_retract_to_pre_nst mtv r
#push-options "--z3rlimit 100"
val mt_retract_to:
mt:mt_p ->
r:offset_t ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt /\ mt_retract_to_pre_nst (B.get h0 mt 0) r))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
// correctness
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let off = MT?.offset mtv0 in
let r = split_offset off r in
MT?.hash_size mtv0 = MT?.hash_size mtv1 /\
MTH.mt_retract_to (mt_lift h0 mt) (U32.v r) == mt_lift h1 mt)))
let mt_retract_to mt r =
let hh0 = HST.get () in
let mtv = !*mt in
let offset = MT?.offset mtv in
let r = split_offset offset r in
let hs = MT?.hs mtv in
mt_retract_to_ hs 0ul (MT?.i mtv) (r + 1ul) (MT?.j mtv);
let hh1 = HST.get () in
RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs);
V.loc_vector_within_included hs 0ul (V.size_of hs);
RV.rv_inv_preserved
(MT?.rhs mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
RV.as_seq_preserved
(MT?.rhs mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
mt *= MT (MT?.hash_size mtv) (MT?.offset mtv) (MT?.i mtv) (r+1ul) hs false (MT?.rhs mtv) (MT?.mroot mtv) (MT?.hash_spec mtv) (MT?.hash_fun mtv);
let hh2 = HST.get () in
RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2;
mt_safe_elts_preserved 0ul hs (MT?.i mtv) (r+1ul) (B.loc_buffer mt) hh1 hh2
#pop-options
/// Client-side verification
private
val mt_verify_:
#hsz:hash_size_t ->
#hash_spec:MTS.hash_fun_t #(U32.v hsz) ->
k:index_t ->
j:index_t{k <= j} ->
mtr:HH.rid ->
p:const_path_p ->
ppos:uint32_t ->
acc:hash #hsz ->
actd:bool ->
hash_fun:hash_fun_t #hsz #hash_spec ->
HST.ST unit
(requires (fun h0 ->
let p = CB.cast p in
path_safe h0 mtr p /\ Rgl?.r_inv (hreg hsz) h0 acc /\
Path?.hash_size (B.get h0 p 0) = hsz /\
HH.disjoint (B.frameOf p) (B.frameOf acc) /\
HH.disjoint mtr (B.frameOf acc) /\
// Below is a very relaxed condition,
// but sufficient to ensure (+) for uint32_t is sound.
ppos <= 64ul - mt_path_length 0ul k j actd /\
ppos + mt_path_length 0ul k j actd <= V.size_of (phashes h0 p)))
(ensures (fun h0 _ h1 ->
let p = CB.cast p in
// memory safety
modifies (B.loc_all_regions_from false (B.frameOf acc)) h0 h1 /\
Rgl?.r_inv (hreg hsz) h1 acc /\
// correctness
Rgl?.r_repr (hreg hsz) h1 acc ==
MTH.mt_verify_ #(U32.v hsz) #hash_spec (U32.v k) (U32.v j) (lift_path h0 mtr p)
(U32.v ppos) (Rgl?.r_repr (hreg hsz) h0 acc) actd)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"MerkleTree.New.High.fst.checked",
"MerkleTree.Low.VectorExtras.fst.checked",
"MerkleTree.Low.Hashfunctions.fst.checked",
"MerkleTree.Low.Datastructures.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.Instances.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Monotonic.HyperHeap.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.All.fst.checked",
"EverCrypt.Helpers.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.Low.fst"
} | [
{
"abbrev": false,
"full_module": "MerkleTree.Low.VectorExtras",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low.Hashfunctions",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low.Datastructures",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "MerkleTree.New.High",
"short_module": "MTH"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Regional.Instances",
"short_module": "RVI"
},
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.HyperHeap",
"short_module": "HH"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": "MHS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.Regional.Instances",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": 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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: MerkleTree.Low.index_t ->
j: MerkleTree.Low.index_t{k <= j} ->
mtr: FStar.Monotonic.HyperHeap.rid ->
p: MerkleTree.Low.const_path_p ->
ppos: LowStar.Vector.uint32_t ->
acc: MerkleTree.Low.Datastructures.hash ->
actd: Prims.bool ->
hash_fun: MerkleTree.Low.Hashfunctions.hash_fun_t
-> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"MerkleTree.Low.Datastructures.hash_size_t",
"MerkleTree.Spec.hash_fun_t",
"FStar.UInt32.v",
"MerkleTree.Low.index_t",
"Prims.b2t",
"FStar.Integers.op_Less_Equals",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Monotonic.HyperHeap.rid",
"MerkleTree.Low.const_path_p",
"LowStar.Vector.uint32_t",
"MerkleTree.Low.Datastructures.hash",
"Prims.bool",
"MerkleTree.Low.Hashfunctions.hash_fun_t",
"FStar.Ghost.hide",
"Prims.op_Equality",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Integers.op_Percent",
"Prims.op_BarBar",
"Prims.op_AmpAmp",
"FStar.Integers.op_Plus",
"Prims.op_Negation",
"MerkleTree.Low.mt_verify_",
"FStar.Integers.op_Slash",
"Prims._assert",
"Prims.eq2",
"Spec.Hash.Definitions.bytes",
"Prims.l_or",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint8",
"LowStar.Regional.__proj__Rgl__item__r_repr",
"MerkleTree.Low.Datastructures.hreg",
"FStar.Seq.Base.index",
"MerkleTree.New.High.hash",
"MerkleTree.Low.lift_path",
"MerkleTree.Low.lift_path_index",
"MerkleTree.Low.path_preserved",
"LowStar.Monotonic.Buffer.loc_all_regions_from",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Buffer.trivial_preorder",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"MerkleTree.Low.__proj__Path__item__hash_size",
"LowStar.Vector.index",
"MerkleTree.Low.__proj__Path__item__hashes",
"MerkleTree.Low.path",
"LowStar.BufferOps.op_Bang_Star",
"MerkleTree.Low.path_p",
"LowStar.ConstBuffer.cast"
] | [
"recursion"
] | false | true | false | false | false | let rec mt_verify_ #hsz #hash_spec k j mtr p ppos acc actd hash_fun =
| let ncp:path_p = CB.cast p in
let hh0 = HST.get () in
if j = 0ul
then ()
else
(let nactd = actd || (j % 2ul = 1ul) in
if k % 2ul = 0ul
then
if j = k || (j = k + 1ul && not actd)
then mt_verify_ (k / 2ul) (j / 2ul) mtr p ppos acc nactd hash_fun
else
let ncpd = !*ncp in
let phash = V.index (Path?.hashes ncpd) ppos in
hash_fun acc phash acc;
let hh1 = HST.get () in
path_preserved mtr ncp (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
lift_path_index hh0 mtr ncp ppos;
assert (Rgl?.r_repr (hreg hsz) hh1 acc ==
hash_spec (Rgl?.r_repr (hreg hsz) hh0 acc)
(S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos)));
mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun
else
let ncpd = !*ncp in
let phash = V.index (Path?.hashes ncpd) ppos in
hash_fun phash acc acc;
let hh1 = HST.get () in
path_preserved mtr ncp (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
lift_path_index hh0 mtr ncp ppos;
assert (Rgl?.r_repr (hreg hsz) hh1 acc ==
hash_spec (S.index (lift_path #hsz hh0 mtr ncp) (U32.v ppos))
(Rgl?.r_repr (hreg hsz) hh0 acc));
mt_verify_ (k / 2ul) (j / 2ul) mtr p (ppos + 1ul) acc nactd hash_fun) | false |
Pulse.Soundness.Comp.fst | Pulse.Soundness.Comp.comp_typing_soundness | val comp_typing_soundness (g:stt_env)
(c:comp)
(uc:universe)
(d:comp_typing g c uc)
: GTot (RT.tot_typing (elab_env g) (elab_comp c) (RT.tm_type uc)) | val comp_typing_soundness (g:stt_env)
(c:comp)
(uc:universe)
(d:comp_typing g c uc)
: GTot (RT.tot_typing (elab_env g) (elab_comp c) (RT.tm_type uc)) | let comp_typing_soundness (g:stt_env)
(c:comp)
(uc:universe)
(d:comp_typing g c uc)
: GTot (RT.tot_typing (elab_env g)
(elab_comp c)
(RT.tm_type uc))
(decreases d)
= match d with
| CT_Tot _ t _ dt ->
tot_typing_soundness dt
| CT_ST _ st d_st ->
let res_typing, pre_typing, post_typing = stc_soundness d_st in
STT.stt_typing res_typing pre_typing post_typing
| CT_STAtomic _ i obs st d_i d_st ->
let i_typing = tot_typing_soundness d_i in
let res_typing, pre_typing, post_typing = stc_soundness d_st in
STT.stt_atomic_typing #(elab_observability obs) res_typing i_typing pre_typing post_typing
| CT_STGhost _ st d_st ->
let res_typing, pre_typing, post_typing = stc_soundness d_st in
STT.stt_ghost_typing res_typing pre_typing post_typing | {
"file_name": "lib/steel/pulse/Pulse.Soundness.Comp.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 84,
"start_col": 0,
"start_line": 61
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Soundness.Comp
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Elaborate.Core
open Pulse.Elaborate
open Pulse.Soundness.Common
module STT = Pulse.Soundness.STT
let stc_soundness
(#g:stt_env)
(#st:st_comp)
(d_st:st_comp_typing g st)
: GTot (RT.tot_typing (elab_env g)
(elab_term st.res)
(RT.tm_type st.u) &
RT.tot_typing (elab_env g)
(elab_term st.pre)
vprop_tm &
RT.tot_typing (elab_env g)
(mk_abs (elab_term st.res) R.Q_Explicit
(elab_term st.post))
(post1_type_bind (elab_term st.res))) =
let STC _ st x dres dpre dpost = d_st in
let res_typing = tot_typing_soundness dres in
let pre_typing = tot_typing_soundness dpre in
calc (==) {
RT.close_term (elab_term (open_term st.post x)) x;
(==) { elab_open_commute st.post x }
RT.close_term (RT.open_term (elab_term st.post) x) x;
(==) {
elab_freevars st.post;
RT.close_open_inverse (elab_term st.post) x
}
elab_term st.post;
};
let post_typing = mk_t_abs_tot g ppname_default dres dpost in
res_typing, pre_typing, post_typing | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.STT.fsti.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"Pulse.Elaborate.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Soundness.Comp.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Soundness.STT",
"short_module": "STT"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 2,
"max_fuel": 2,
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Soundness.Common.stt_env ->
c: Pulse.Syntax.Base.comp ->
uc: Pulse.Syntax.Base.universe ->
d: Pulse.Typing.comp_typing g c uc
-> Prims.GTot
(FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g)
(Pulse.Elaborate.Pure.elab_comp c)
(FStar.Reflection.Typing.tm_type uc)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Soundness.Common.stt_env",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.universe",
"Pulse.Typing.comp_typing",
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.universe_of",
"Pulse.Soundness.Common.tot_typing_soundness",
"Pulse.Syntax.Pure.tm_type",
"Pulse.Syntax.Base.st_comp",
"Pulse.Typing.st_comp_typing",
"FStar.Reflection.Typing.tot_typing",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"FStar.Reflection.Typing.tm_type",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Reflection.Util.vprop_tm",
"Pulse.Reflection.Util.mk_abs",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Pulse.Soundness.Common.post1_type_bind",
"Pulse.Soundness.STT.stt_typing",
"Pulse.Elaborate.Pure.elab_comp",
"FStar.Pervasives.Native.tuple3",
"Pulse.Soundness.Comp.stc_soundness",
"Pulse.Syntax.Base.observability",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_inames",
"Pulse.Soundness.STT.stt_atomic_typing",
"Pulse.Elaborate.Pure.elab_observability",
"Pulse.Soundness.STT.stt_ghost_typing"
] | [] | false | false | false | false | false | let comp_typing_soundness (g: stt_env) (c: comp) (uc: universe) (d: comp_typing g c uc)
: GTot (RT.tot_typing (elab_env g) (elab_comp c) (RT.tm_type uc)) (decreases d) =
| match d with
| CT_Tot _ t _ dt -> tot_typing_soundness dt
| CT_ST _ st d_st ->
let res_typing, pre_typing, post_typing = stc_soundness d_st in
STT.stt_typing res_typing pre_typing post_typing
| CT_STAtomic _ i obs st d_i d_st ->
let i_typing = tot_typing_soundness d_i in
let res_typing, pre_typing, post_typing = stc_soundness d_st in
STT.stt_atomic_typing #(elab_observability obs) res_typing i_typing pre_typing post_typing
| CT_STGhost _ st d_st ->
let res_typing, pre_typing, post_typing = stc_soundness d_st in
STT.stt_ghost_typing res_typing pre_typing post_typing | false |
MerkleTree.Low.fst | MerkleTree.Low.mt_flush_to | val mt_flush_to:
mt:mt_p ->
idx:offset_t ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
// correctness
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let off = MT?.offset mtv0 in
let idx = split_offset off idx in
MT?.hash_size mtv0 = MT?.hash_size mtv1 /\
MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt))) | val mt_flush_to:
mt:mt_p ->
idx:offset_t ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
// correctness
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let off = MT?.offset mtv0 in
let idx = split_offset off idx in
MT?.hash_size mtv0 = MT?.hash_size mtv1 /\
MTH.mt_flush_to (mt_lift h0 mt) (U32.v idx) == mt_lift h1 mt))) | let mt_flush_to mt idx =
let hh0 = HST.get () in
let mtv = !*mt in
let offset = MT?.offset mtv in
let j = MT?.j mtv in
let hsz = MT?.hash_size mtv in
let idx = split_offset offset idx in
let hs = MT?.hs mtv in
mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv));
let hh1 = HST.get () in
RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs);
V.loc_vector_within_included hs 0ul (V.size_of hs);
RV.rv_inv_preserved
(MT?.rhs mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
RV.as_seq_preserved
(MT?.rhs mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv)
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
hh0 hh1;
mt *= MT (MT?.hash_size mtv)
(MT?.offset mtv) idx (MT?.j mtv)
hs
(MT?.rhs_ok mtv) (MT?.rhs mtv)
(MT?.mroot mtv)
(MT?.hash_spec mtv) (MT?.hash_fun mtv);
let hh2 = HST.get () in
RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2;
mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2 | {
"file_name": "src/MerkleTree.Low.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 73,
"end_line": 2492,
"start_col": 0,
"start_line": 2451
} | module MerkleTree.Low
open EverCrypt.Helpers
open FStar.All
open FStar.Integers
open FStar.Mul
open LowStar.Buffer
open LowStar.BufferOps
open LowStar.Vector
open LowStar.Regional
open LowStar.RVector
open LowStar.Regional.Instances
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module MHS = FStar.Monotonic.HyperStack
module HH = FStar.Monotonic.HyperHeap
module B = LowStar.Buffer
module CB = LowStar.ConstBuffer
module V = LowStar.Vector
module RV = LowStar.RVector
module RVI = LowStar.Regional.Instances
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module MTH = MerkleTree.New.High
module MTS = MerkleTree.Spec
open Lib.IntTypes
open MerkleTree.Low.Datastructures
open MerkleTree.Low.Hashfunctions
open MerkleTree.Low.VectorExtras
#set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
type const_pointer (a:Type0) = b:CB.const_buffer a{CB.length b == 1 /\ CB.qual_of b == CB.MUTABLE}
/// Low-level Merkle tree data structure
///
// NOTE: because of a lack of 64-bit LowStar.Buffer support, currently
// we cannot change below to some other types.
type index_t = uint32_t
let uint32_32_max = 4294967295ul
inline_for_extraction
let uint32_max = 4294967295UL
let uint64_max = 18446744073709551615UL
let offset_range_limit = uint32_max
type offset_t = uint64_t
inline_for_extraction noextract unfold let u32_64 = Int.Cast.uint32_to_uint64
inline_for_extraction noextract unfold let u64_32 = Int.Cast.uint64_to_uint32
private inline_for_extraction
let offsets_connect (x:offset_t) (y:offset_t): Tot bool = y >= x && (y - x) <= offset_range_limit
private inline_for_extraction
let split_offset (tree:offset_t) (index:offset_t{offsets_connect tree index}): Tot index_t =
[@inline_let] let diff = U64.sub_mod index tree in
assert (diff <= offset_range_limit);
Int.Cast.uint64_to_uint32 diff
private inline_for_extraction
let add64_fits (x:offset_t) (i:index_t): Tot bool = uint64_max - x >= (u32_64 i)
private inline_for_extraction
let join_offset (tree:offset_t) (i:index_t{add64_fits tree i}): Tot (r:offset_t{offsets_connect tree r}) =
U64.add tree (u32_64 i)
inline_for_extraction val merkle_tree_size_lg: uint32_t
let merkle_tree_size_lg = 32ul
// A Merkle tree `MT i j hs rhs_ok rhs` stores all necessary hashes to generate
// a Merkle path for each element from the index `i` to `j-1`.
// - Parameters
// `hs`: a 2-dim store for hashes, where `hs[0]` contains leaf hash values.
// `rhs_ok`: to check the rightmost hashes are up-to-date
// `rhs`: a store for "rightmost" hashes, manipulated only when required to
// calculate some merkle paths that need the rightmost hashes
// as a part of them.
// `mroot`: during the construction of `rhs` we can also calculate the Merkle
// root of the tree. If `rhs_ok` is true then it has the up-to-date
// root value.
noeq type merkle_tree =
| MT: hash_size:hash_size_t ->
offset:offset_t ->
i:index_t -> j:index_t{i <= j /\ add64_fits offset j} ->
hs:hash_vv hash_size {V.size_of hs = merkle_tree_size_lg} ->
rhs_ok:bool ->
rhs:hash_vec #hash_size {V.size_of rhs = merkle_tree_size_lg} ->
mroot:hash #hash_size ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) ->
hash_fun:hash_fun_t #hash_size #hash_spec ->
merkle_tree
type mt_p = B.pointer merkle_tree
type const_mt_p = const_pointer merkle_tree
inline_for_extraction
let merkle_tree_conditions (#hsz:Ghost.erased hash_size_t) (offset:uint64_t) (i j:uint32_t) (hs:hash_vv hsz) (rhs_ok:bool) (rhs:hash_vec #hsz) (mroot:hash #hsz): Tot bool =
j >= i && add64_fits offset j &&
V.size_of hs = merkle_tree_size_lg &&
V.size_of rhs = merkle_tree_size_lg
// The maximum number of currently held elements in the tree is (2^32 - 1).
// cwinter: even when using 64-bit indices, we fail if the underlying 32-bit
// vector is full; this can be fixed if necessary.
private inline_for_extraction
val mt_not_full_nst: mtv:merkle_tree -> Tot bool
let mt_not_full_nst mtv = MT?.j mtv < uint32_32_max
val mt_not_full: HS.mem -> mt_p -> GTot bool
let mt_not_full h mt = mt_not_full_nst (B.get h mt 0)
/// (Memory) Safety
val offset_of: i:index_t -> Tot index_t
let offset_of i = if i % 2ul = 0ul then i else i - 1ul
// `mt_safe_elts` says that it is safe to access an element from `i` to `j - 1`
// at level `lv` in the Merkle tree, i.e., hs[lv][k] (i <= k < j) is a valid
// element.
inline_for_extraction noextract
val mt_safe_elts:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
GTot Type0 (decreases (32 - U32.v lv))
let rec mt_safe_elts #hsz h lv hs i j =
if lv = merkle_tree_size_lg then true
else (let ofs = offset_of i in
V.size_of (V.get h hs lv) == j - ofs /\
mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul))
#push-options "--initial_fuel 1 --max_fuel 1"
val mt_safe_elts_constr:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (V.size_of (V.get h hs lv) == j - offset_of i /\
mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)))
(ensures (mt_safe_elts #hsz h lv hs i j))
let mt_safe_elts_constr #_ h lv hs i j = ()
val mt_safe_elts_head:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (mt_safe_elts #hsz h lv hs i j))
(ensures (V.size_of (V.get h hs lv) == j - offset_of i))
let mt_safe_elts_head #_ h lv hs i j = ()
val mt_safe_elts_rec:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
Lemma (requires (mt_safe_elts #hsz h lv hs i j))
(ensures (mt_safe_elts #hsz h (lv + 1ul) hs (i / 2ul) (j / 2ul)))
let mt_safe_elts_rec #_ h lv hs i j = ()
val mt_safe_elts_init:
#hsz:hash_size_t ->
h:HS.mem -> lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
Lemma (requires (V.forall_ h hs lv (V.size_of hs)
(fun hv -> V.size_of hv = 0ul)))
(ensures (mt_safe_elts #hsz h lv hs 0ul 0ul))
(decreases (32 - U32.v lv))
let rec mt_safe_elts_init #hsz h lv hs =
if lv = merkle_tree_size_lg then ()
else mt_safe_elts_init #hsz h (lv + 1ul) hs
#pop-options
val mt_safe_elts_preserved:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{j >= i} ->
p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (V.live h0 hs /\
mt_safe_elts #hsz h0 lv hs i j /\
loc_disjoint p (V.loc_vector_within hs lv (V.size_of hs)) /\
modifies p h0 h1))
(ensures (mt_safe_elts #hsz h1 lv hs i j))
(decreases (32 - U32.v lv))
[SMTPat (V.live h0 hs);
SMTPat (mt_safe_elts #hsz h0 lv hs i j);
SMTPat (loc_disjoint p (RV.loc_rvector hs));
SMTPat (modifies p h0 h1)]
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let rec mt_safe_elts_preserved #hsz lv hs i j p h0 h1 =
if lv = merkle_tree_size_lg then ()
else (V.get_preserved hs lv p h0 h1;
mt_safe_elts_preserved #hsz (lv + 1ul) hs (i / 2ul) (j / 2ul) p h0 h1)
#pop-options
// `mt_safe` is the invariant of a Merkle tree through its lifetime.
// It includes liveness, regionality, disjointness (to each data structure),
// and valid element access (`mt_safe_elts`).
inline_for_extraction noextract
val mt_safe: HS.mem -> mt_p -> GTot Type0
let mt_safe h mt =
B.live h mt /\ B.freeable mt /\
(let mtv = B.get h mt 0 in
// Liveness & Accessibility
RV.rv_inv h (MT?.hs mtv) /\
RV.rv_inv h (MT?.rhs mtv) /\
Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\
mt_safe_elts h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) /\
// Regionality
HH.extends (V.frameOf (MT?.hs mtv)) (B.frameOf mt) /\
HH.extends (V.frameOf (MT?.rhs mtv)) (B.frameOf mt) /\
HH.extends (B.frameOf (MT?.mroot mtv)) (B.frameOf mt) /\
HH.disjoint (V.frameOf (MT?.hs mtv)) (V.frameOf (MT?.rhs mtv)) /\
HH.disjoint (V.frameOf (MT?.hs mtv)) (B.frameOf (MT?.mroot mtv)) /\
HH.disjoint (V.frameOf (MT?.rhs mtv)) (B.frameOf (MT?.mroot mtv)))
// Since a Merkle tree satisfies regionality, it's ok to take all regions from
// a tree pointer as a location of the tree.
val mt_loc: mt_p -> GTot loc
let mt_loc mt = B.loc_all_regions_from false (B.frameOf mt)
val mt_safe_preserved:
mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (mt_safe h0 mt /\
loc_disjoint p (mt_loc mt) /\
modifies p h0 h1))
(ensures (B.get h0 mt 0 == B.get h1 mt 0 /\
mt_safe h1 mt))
let mt_safe_preserved mt p h0 h1 =
assert (loc_includes (mt_loc mt) (B.loc_buffer mt));
let mtv = B.get h0 mt 0 in
assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.hs mtv)));
assert (loc_includes (mt_loc mt) (RV.loc_rvector (MT?.rhs mtv)));
assert (loc_includes (mt_loc mt) (V.loc_vector (MT?.hs mtv)));
assert (loc_includes (mt_loc mt)
(B.loc_all_regions_from false (B.frameOf (MT?.mroot mtv))));
RV.rv_inv_preserved (MT?.hs mtv) p h0 h1;
RV.rv_inv_preserved (MT?.rhs mtv) p h0 h1;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) p h0 h1;
V.loc_vector_within_included (MT?.hs mtv) 0ul (V.size_of (MT?.hs mtv));
mt_safe_elts_preserved 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv) p h0 h1
/// Lifting to a high-level Merkle tree structure
val mt_safe_elts_spec:
#hsz:hash_size_t ->
h:HS.mem ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{j >= i} ->
Lemma (requires (RV.rv_inv h hs /\
mt_safe_elts #hsz h lv hs i j))
(ensures (MTH.hs_wf_elts #(U32.v hsz)
(U32.v lv) (RV.as_seq h hs)
(U32.v i) (U32.v j)))
(decreases (32 - U32.v lv))
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let rec mt_safe_elts_spec #_ h lv hs i j =
if lv = merkle_tree_size_lg then ()
else mt_safe_elts_spec h (lv + 1ul) hs (i / 2ul) (j / 2ul)
#pop-options
val merkle_tree_lift:
h:HS.mem ->
mtv:merkle_tree{
RV.rv_inv h (MT?.hs mtv) /\
RV.rv_inv h (MT?.rhs mtv) /\
Rgl?.r_inv (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv) /\
mt_safe_elts #(MT?.hash_size mtv) h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv)} ->
GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size mtv)) {MTH.mt_wf_elts #_ r})
let merkle_tree_lift h mtv =
mt_safe_elts_spec h 0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv);
MTH.MT #(U32.v (MT?.hash_size mtv))
(U32.v (MT?.i mtv))
(U32.v (MT?.j mtv))
(RV.as_seq h (MT?.hs mtv))
(MT?.rhs_ok mtv)
(RV.as_seq h (MT?.rhs mtv))
(Rgl?.r_repr (hreg (MT?.hash_size mtv)) h (MT?.mroot mtv))
(Ghost.reveal (MT?.hash_spec mtv))
val mt_lift:
h:HS.mem -> mt:mt_p{mt_safe h mt} ->
GTot (r:MTH.merkle_tree #(U32.v (MT?.hash_size (B.get h mt 0))) {MTH.mt_wf_elts #_ r})
let mt_lift h mt =
merkle_tree_lift h (B.get h mt 0)
val mt_preserved:
mt:mt_p -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (mt_safe h0 mt /\
loc_disjoint p (mt_loc mt) /\
modifies p h0 h1))
(ensures (mt_safe_preserved mt p h0 h1;
mt_lift h0 mt == mt_lift h1 mt))
let mt_preserved mt p h0 h1 =
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(B.loc_buffer mt));
B.modifies_buffer_elim mt p h0 h1;
assert (B.get h0 mt 0 == B.get h1 mt 0);
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(RV.loc_rvector (MT?.hs (B.get h0 mt 0))));
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(RV.loc_rvector (MT?.rhs (B.get h0 mt 0))));
assert (loc_includes (B.loc_all_regions_from false (B.frameOf mt))
(B.loc_buffer (MT?.mroot (B.get h0 mt 0))));
RV.as_seq_preserved (MT?.hs (B.get h0 mt 0)) p h0 h1;
RV.as_seq_preserved (MT?.rhs (B.get h0 mt 0)) p h0 h1;
B.modifies_buffer_elim (MT?.mroot (B.get h0 mt 0)) p h0 h1
/// Construction
// Note that the public function for creation is `mt_create` defined below,
// which builds a tree with an initial hash.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
private
val create_empty_mt:
hash_size:hash_size_t ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hash_size)) ->
hash_fun:hash_fun_t #hash_size #hash_spec ->
r:HST.erid ->
HST.ST mt_p
(requires (fun _ -> true))
(ensures (fun h0 mt h1 ->
let dmt = B.get h1 mt 0 in
// memory safety
B.frameOf mt = r /\
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
mt_not_full h1 mt /\
// correctness
MT?.hash_size dmt = hash_size /\
MT?.offset dmt = 0UL /\
merkle_tree_lift h1 dmt == MTH.create_empty_mt #_ #(Ghost.reveal hash_spec) ()))
let create_empty_mt hsz hash_spec hash_fun r =
[@inline_let] let hrg = hreg hsz in
[@inline_let] let hvrg = hvreg hsz in
[@inline_let] let hvvrg = hvvreg hsz in
let hs_region = HST.new_region r in
let hs = RV.alloc_rid hvrg merkle_tree_size_lg hs_region in
let h0 = HST.get () in
mt_safe_elts_init #hsz h0 0ul hs;
let rhs_region = HST.new_region r in
let rhs = RV.alloc_rid hrg merkle_tree_size_lg rhs_region in
let h1 = HST.get () in
assert (RV.as_seq h1 rhs == S.create 32 (MTH.hash_init #(U32.v hsz)));
RV.rv_inv_preserved hs (V.loc_vector rhs) h0 h1;
RV.as_seq_preserved hs (V.loc_vector rhs) h0 h1;
V.loc_vector_within_included hs 0ul (V.size_of hs);
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul (V.loc_vector rhs) h0 h1;
let mroot_region = HST.new_region r in
let mroot = rg_alloc hrg mroot_region in
let h2 = HST.get () in
RV.as_seq_preserved hs loc_none h1 h2;
RV.as_seq_preserved rhs loc_none h1 h2;
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h1 h2;
let mt = B.malloc r (MT hsz 0UL 0ul 0ul hs false rhs mroot hash_spec hash_fun) 1ul in
let h3 = HST.get () in
RV.as_seq_preserved hs loc_none h2 h3;
RV.as_seq_preserved rhs loc_none h2 h3;
Rgl?.r_sep hrg mroot loc_none h2 h3;
mt_safe_elts_preserved #hsz 0ul hs 0ul 0ul loc_none h2 h3;
mt
#pop-options
/// Destruction (free)
val mt_free: mt:mt_p ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt))
(ensures (fun h0 _ h1 -> modifies (mt_loc mt) h0 h1))
#push-options "--z3rlimit 100"
let mt_free mt =
let mtv = !*mt in
RV.free (MT?.hs mtv);
RV.free (MT?.rhs mtv);
[@inline_let] let rg = hreg (MT?.hash_size mtv) in
rg_free rg (MT?.mroot mtv);
B.free mt
#pop-options
/// Insertion
private
val as_seq_sub_upd:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
h:HS.mem -> rv:rvector #a #rst rg ->
i:uint32_t{i < V.size_of rv} -> v:Rgl?.repr rg ->
Lemma (requires (RV.rv_inv h rv))
(ensures (S.equal (S.upd (RV.as_seq h rv) (U32.v i) v)
(S.append
(RV.as_seq_sub h rv 0ul i)
(S.cons v (RV.as_seq_sub h rv (i + 1ul) (V.size_of rv))))))
#push-options "--z3rlimit 20"
let as_seq_sub_upd #a #rst #rg h rv i v =
Seq.Properties.slice_upd (RV.as_seq h rv) 0 (U32.v i) (U32.v i) v;
Seq.Properties.slice_upd (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i) v;
RV.as_seq_seq_slice rg h (V.as_seq h rv)
0 (U32.v (V.size_of rv)) 0 (U32.v i);
assert (S.equal (S.slice (RV.as_seq h rv) 0 (U32.v i))
(RV.as_seq_sub h rv 0ul i));
RV.as_seq_seq_slice rg h (V.as_seq h rv)
0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv));
assert (S.equal (S.slice (RV.as_seq h rv) (U32.v i + 1) (U32.v (V.size_of rv)))
(RV.as_seq_sub h rv (i + 1ul) (V.size_of rv)));
assert (S.index (S.upd (RV.as_seq h rv) (U32.v i) v) (U32.v i) == v)
#pop-options
// `hash_vv_insert_copy` inserts a hash element at a level `lv`, by copying
// and pushing its content to `hs[lv]`. For detailed insertion procedure, see
// `insert_` and `mt_insert`.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1"
private
inline_for_extraction
val hash_vv_insert_copy:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (V.frameOf hs) (B.frameOf v) /\
mt_safe_elts #hsz h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 v /\
V.size_of (V.get h1 hs lv) == j + 1ul - offset_of (Ghost.reveal i) /\
V.size_of (V.get h1 hs lv) == V.size_of (V.get h0 hs lv) + 1ul /\
mt_safe_elts #hsz h1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul) /\
RV.rv_loc_elems h0 hs (lv + 1ul) (V.size_of hs) ==
RV.rv_loc_elems h1 hs (lv + 1ul) (V.size_of hs) /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.hashess_insert
(U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 v))) /\
S.equal (S.index (RV.as_seq h1 hs) (U32.v lv))
(S.snoc (S.index (RV.as_seq h0 hs) (U32.v lv))
(Rgl?.r_repr (hreg hsz) h0 v))))
let hash_vv_insert_copy #hsz lv i j hs v =
let hh0 = HST.get () in
mt_safe_elts_rec hh0 lv hs (Ghost.reveal i) j;
/// 1) Insert an element at the level `lv`, where the new vector is not yet
/// connected to `hs`.
let ihv = RV.insert_copy (hcpy hsz) (V.index hs lv) v in
let hh1 = HST.get () in
// 1-0) Basic disjointness conditions
V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
// 1-1) For the `modifies` postcondition.
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
// 1-2) Preservation
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-3) For `mt_safe_elts`
assert (V.size_of ihv == j + 1ul - offset_of (Ghost.reveal i)); // head updated
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet
// 1-4) For the `rv_inv` postcondition
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v lv);
RV.rv_elems_inv_preserved
hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs))
(U32.v lv + 1) (U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
(U32.v lv + 1) (U32.v (V.size_of hs));
RV.rv_elems_inv_preserved
hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
// assert (rv_itself_inv hh1 hs);
// assert (elems_reg hh1 hs);
// 1-5) Correctness
assert (S.equal (RV.as_seq hh1 ihv)
(S.snoc (RV.as_seq hh0 (V.get hh0 hs lv)) (Rgl?.r_repr (hreg hsz) hh0 v)));
/// 2) Assign the updated vector to `hs` at the level `lv`.
RV.assign hs lv ihv;
let hh2 = HST.get () in
// 2-1) For the `modifies` postcondition.
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2);
// 2-2) Preservation
Rgl?.r_sep (hreg hsz) v (RV.loc_rvector hs) hh1 hh2;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-3) For `mt_safe_elts`
assert (V.size_of (V.get hh2 hs lv) == j + 1ul - offset_of (Ghost.reveal i));
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-4) Correctness
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector ihv) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector ihv) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append
(RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 ihv)
(RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 ihv)
#pop-options
private
val insert_index_helper_even:
lv:uint32_t{lv < merkle_tree_size_lg} ->
j:index_t{U32.v j < pow2 (32 - U32.v lv) - 1} ->
Lemma (requires (j % 2ul <> 1ul))
(ensures (U32.v j % 2 <> 1 /\ j / 2ul == (j + 1ul) / 2ul))
let insert_index_helper_even lv j = ()
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
private
val insert_index_helper_odd:
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:index_t ->
j:index_t{i <= j && U32.v j < pow2 (32 - U32.v lv) - 1} ->
Lemma (requires (j % 2ul = 1ul /\
j < uint32_32_max))
(ensures (U32.v j % 2 = 1 /\
U32.v (j / 2ul) < pow2 (32 - U32.v (lv + 1ul)) - 1 /\
(j + 1ul) / 2ul == j / 2ul + 1ul /\
j - offset_of i > 0ul))
let insert_index_helper_odd lv i j = ()
#pop-options
private
val loc_union_assoc_4:
a:loc -> b:loc -> c:loc -> d:loc ->
Lemma (loc_union (loc_union a b) (loc_union c d) ==
loc_union (loc_union a c) (loc_union b d))
let loc_union_assoc_4 a b c d =
loc_union_assoc (loc_union a b) c d;
loc_union_assoc a b c;
loc_union_assoc a c b;
loc_union_assoc (loc_union a c) b d
private
val insert_modifies_rec_helper:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
aloc:loc ->
h:HS.mem ->
Lemma (loc_union
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
aloc)
(loc_union
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
aloc) ==
loc_union
(loc_union
(RV.rv_loc_elems h hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
aloc)
#push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2"
let insert_modifies_rec_helper #hsz lv hs aloc h =
assert (V.loc_vector_within hs lv (V.size_of hs) ==
loc_union (V.loc_vector_within hs lv (lv + 1ul))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)));
RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs));
assert (RV.rv_loc_elems h hs lv (V.size_of hs) ==
loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)));
// Applying some association rules...
loc_union_assoc
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) aloc
(loc_union
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
aloc);
loc_union_assoc
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) aloc aloc;
loc_union_assoc
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
aloc;
loc_union_assoc_4
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
#pop-options
private
val insert_modifies_union_loc_weakening:
l1:loc -> l2:loc -> l3:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (modifies l1 h0 h1))
(ensures (modifies (loc_union (loc_union l1 l2) l3) h0 h1))
let insert_modifies_union_loc_weakening l1 l2 l3 h0 h1 =
B.loc_includes_union_l l1 l2 l1;
B.loc_includes_union_l (loc_union l1 l2) l3 (loc_union l1 l2)
private
val insert_snoc_last_helper:
#a:Type -> s:S.seq a{S.length s > 0} -> v:a ->
Lemma (S.index (S.snoc s v) (S.length s - 1) == S.last s)
let insert_snoc_last_helper #a s v = ()
private
val rv_inv_rv_elems_reg:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
h:HS.mem -> rv:rvector rg ->
i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} ->
Lemma (requires (RV.rv_inv h rv))
(ensures (RV.rv_elems_reg h rv i j))
let rv_inv_rv_elems_reg #a #rst #rg h rv i j = ()
// `insert_` recursively inserts proper hashes to each level `lv` by
// accumulating a compressed hash. For example, if there are three leaf elements
// in the tree, `insert_` will change `hs` as follow:
// (`hij` is a compressed hash from `hi` to `hj`)
//
// BEFORE INSERTION AFTER INSERTION
// lv
// 0 h0 h1 h2 ====> h0 h1 h2 h3
// 1 h01 h01 h23
// 2 h03
//
private
val insert_:
#hsz:hash_size_t ->
#hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
i:Ghost.erased index_t ->
j:index_t{
Ghost.reveal i <= j &&
U32.v j < pow2 (32 - U32.v lv) - 1 &&
j < uint32_32_max} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
acc:hash #hsz ->
hash_fun:hash_fun_t #hsz #hash_spec ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
Rgl?.r_inv (hreg hsz) h0 acc /\
HH.disjoint (V.frameOf hs) (B.frameOf acc) /\
mt_safe_elts h0 lv hs (Ghost.reveal i) j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(loc_union
(RV.rv_loc_elems h0 hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
h0 h1 /\
RV.rv_inv h1 hs /\
Rgl?.r_inv (hreg hsz) h1 acc /\
mt_safe_elts h1 lv hs (Ghost.reveal i) (j + 1ul) /\
// correctness
(mt_safe_elts_spec h0 lv hs (Ghost.reveal i) j;
S.equal (RV.as_seq h1 hs)
(MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq h0 hs) (Rgl?.r_repr (hreg hsz) h0 acc)))))
(decreases (U32.v j))
#push-options "--z3rlimit 800 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec insert_ #hsz #hash_spec lv i j hs acc hash_fun =
let hh0 = HST.get () in
hash_vv_insert_copy lv i j hs acc;
let hh1 = HST.get () in
// Base conditions
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
assert (V.size_of (V.get hh1 hs lv) == j + 1ul - offset_of (Ghost.reveal i));
assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul));
if j % 2ul = 1ul
then (insert_index_helper_odd lv (Ghost.reveal i) j;
assert (S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) > 0);
let lvhs = V.index hs lv in
assert (U32.v (V.size_of lvhs) ==
S.length (S.index (RV.as_seq hh0 hs) (U32.v lv)) + 1);
assert (V.size_of lvhs > 1ul);
/// 3) Update the accumulator `acc`.
hash_vec_rv_inv_r_inv hh1 (V.get hh1 hs lv) (V.size_of (V.get hh1 hs lv) - 2ul);
assert (Rgl?.r_inv (hreg hsz) hh1 acc);
hash_fun (V.index lvhs (V.size_of lvhs - 2ul)) acc acc;
let hh2 = HST.get () in
// 3-1) For the `modifies` postcondition
assert (modifies (B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2);
assert (modifies
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh0 hh2);
// 3-2) Preservation
RV.rv_inv_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.as_seq_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(B.loc_region_only false (B.frameOf acc)) hh1 hh2;
assert (RV.rv_inv hh2 hs);
assert (Rgl?.r_inv (hreg hsz) hh2 acc);
// 3-3) For `mt_safe_elts`
V.get_preserved hs lv
(B.loc_region_only false (B.frameOf acc)) hh1 hh2; // head preserved
mt_safe_elts_preserved
(lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul)
(B.loc_region_only false (B.frameOf acc)) hh1 hh2; // tail preserved
// 3-4) Correctness
insert_snoc_last_helper
(RV.as_seq hh0 (V.get hh0 hs lv))
(Rgl?.r_repr (hreg hsz) hh0 acc);
assert (S.equal (Rgl?.r_repr (hreg hsz) hh2 acc) // `nacc` in `MTH.insert_`
((Ghost.reveal hash_spec)
(S.last (S.index (RV.as_seq hh0 hs) (U32.v lv)))
(Rgl?.r_repr (hreg hsz) hh0 acc)));
/// 4) Recursion
insert_ (lv + 1ul)
(Ghost.hide (Ghost.reveal i / 2ul)) (j / 2ul)
hs acc hash_fun;
let hh3 = HST.get () in
// 4-0) Memory safety brought from the postcondition of the recursion
assert (RV.rv_inv hh3 hs);
assert (Rgl?.r_inv (hreg hsz) hh3 acc);
assert (modifies (loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh2 hh3);
assert (modifies
(loc_union
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc)))
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc))))
hh0 hh3);
// 4-1) For `mt_safe_elts`
rv_inv_rv_elems_reg hh2 hs (lv + 1ul) (V.size_of hs);
RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs);
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)));
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(B.loc_all_regions_from false (B.frameOf acc)));
V.get_preserved hs lv
(loc_union
(loc_union
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh2 hh3;
assert (V.size_of (V.get hh3 hs lv) ==
j + 1ul - offset_of (Ghost.reveal i)); // head preserved
assert (mt_safe_elts hh3 (lv + 1ul) hs
(Ghost.reveal i / 2ul) (j / 2ul + 1ul)); // tail by recursion
mt_safe_elts_constr hh3 lv hs (Ghost.reveal i) (j + 1ul);
assert (mt_safe_elts hh3 lv hs (Ghost.reveal i) (j + 1ul));
// 4-2) Correctness
mt_safe_elts_spec hh2 (lv + 1ul) hs (Ghost.reveal i / 2ul) (j / 2ul);
assert (S.equal (RV.as_seq hh3 hs)
(MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv + 1) (U32.v (Ghost.reveal i) / 2) (U32.v j / 2)
(RV.as_seq hh2 hs) (Rgl?.r_repr (hreg hsz) hh2 acc)));
mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j;
MTH.insert_rec #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc);
assert (S.equal (RV.as_seq hh3 hs)
(MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))))
else (insert_index_helper_even lv j;
// memory safety
assert (mt_safe_elts hh1 (lv + 1ul) hs (Ghost.reveal i / 2ul) ((j + 1ul) / 2ul));
mt_safe_elts_constr hh1 lv hs (Ghost.reveal i) (j + 1ul);
assert (mt_safe_elts hh1 lv hs (Ghost.reveal i) (j + 1ul));
assert (modifies
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
hh0 hh1);
insert_modifies_union_loc_weakening
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc))
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc)))
hh0 hh1;
// correctness
mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j;
MTH.insert_base #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc);
assert (S.equal (RV.as_seq hh1 hs)
(MTH.insert_ #(U32.v hsz) #(Ghost.reveal hash_spec) (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))));
/// 5) Proving the postcondition after recursion
let hh4 = HST.get () in
// 5-1) For the `modifies` postcondition.
assert (modifies
(loc_union
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(B.loc_all_regions_from false (B.frameOf acc)))
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf acc))))
hh0 hh4);
insert_modifies_rec_helper
lv hs (B.loc_all_regions_from false (B.frameOf acc)) hh0;
// 5-2) For `mt_safe_elts`
assert (mt_safe_elts hh4 lv hs (Ghost.reveal i) (j + 1ul));
// 5-3) Preservation
assert (RV.rv_inv hh4 hs);
assert (Rgl?.r_inv (hreg hsz) hh4 acc);
// 5-4) Correctness
mt_safe_elts_spec hh0 lv hs (Ghost.reveal i) j;
assert (S.equal (RV.as_seq hh4 hs)
(MTH.insert_ #(U32.v hsz) #hash_spec (U32.v lv) (U32.v (Ghost.reveal i)) (U32.v j)
(RV.as_seq hh0 hs) (Rgl?.r_repr (hreg hsz) hh0 acc))) // QED
#pop-options
private inline_for_extraction
val mt_insert_pre_nst: mtv:merkle_tree -> v:hash #(MT?.hash_size mtv) -> Tot bool
let mt_insert_pre_nst mtv v = mt_not_full_nst mtv && add64_fits (MT?.offset mtv) ((MT?.j mtv) + 1ul)
val mt_insert_pre: #hsz:Ghost.erased hash_size_t -> mt:const_mt_p -> v:hash #hsz -> HST.ST bool
(requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ (MT?.hash_size (B.get h0 (CB.cast mt) 0)) = Ghost.reveal hsz))
(ensures (fun _ _ _ -> True))
let mt_insert_pre #hsz mt v =
let mt = !*(CB.cast mt) in
assert (MT?.hash_size mt == (MT?.hash_size mt));
mt_insert_pre_nst mt v
// `mt_insert` inserts a hash to a Merkle tree. Note that this operation
// manipulates the content in `v`, since it uses `v` as an accumulator during
// insertion.
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
val mt_insert:
hsz:Ghost.erased hash_size_t ->
mt:mt_p -> v:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
let dmt = B.get h0 mt 0 in
mt_safe h0 mt /\
Rgl?.r_inv (hreg hsz) h0 v /\
HH.disjoint (B.frameOf mt) (B.frameOf v) /\
MT?.hash_size dmt = Ghost.reveal hsz /\
mt_insert_pre_nst dmt v))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(mt_loc mt)
(B.loc_all_regions_from false (B.frameOf v)))
h0 h1 /\
mt_safe h1 mt /\
// correctness
MT?.hash_size (B.get h1 mt 0) = Ghost.reveal hsz /\
mt_lift h1 mt == MTH.mt_insert (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 v)))
#pop-options
#push-options "--z3rlimit 40"
let mt_insert hsz mt v =
let hh0 = HST.get () in
let mtv = !*mt in
let hs = MT?.hs mtv in
let hsz = MT?.hash_size mtv in
insert_ #hsz #(Ghost.reveal (MT?.hash_spec mtv)) 0ul (Ghost.hide (MT?.i mtv)) (MT?.j mtv) hs v (MT?.hash_fun mtv);
let hh1 = HST.get () in
RV.rv_loc_elems_included hh0 (MT?.hs mtv) 0ul (V.size_of hs);
V.loc_vector_within_included hs 0ul (V.size_of hs);
RV.rv_inv_preserved
(MT?.rhs mtv)
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf v)))
hh0 hh1;
RV.as_seq_preserved
(MT?.rhs mtv)
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf v)))
hh0 hh1;
Rgl?.r_sep (hreg hsz) (MT?.mroot mtv)
(loc_union
(loc_union
(RV.rv_loc_elems hh0 hs 0ul (V.size_of hs))
(V.loc_vector_within hs 0ul (V.size_of hs)))
(B.loc_all_regions_from false (B.frameOf v)))
hh0 hh1;
mt *= MT (MT?.hash_size mtv)
(MT?.offset mtv)
(MT?.i mtv)
(MT?.j mtv + 1ul)
(MT?.hs mtv)
false // `rhs` is always deprecated right after an insertion.
(MT?.rhs mtv)
(MT?.mroot mtv)
(MT?.hash_spec mtv)
(MT?.hash_fun mtv);
let hh2 = HST.get () in
RV.rv_inv_preserved
(MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.rv_inv_preserved
(MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved
(MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved
(MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
Rgl?.r_sep (hreg hsz) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2;
mt_safe_elts_preserved
0ul (MT?.hs mtv) (MT?.i mtv) (MT?.j mtv + 1ul) (B.loc_buffer mt)
hh1 hh2
#pop-options
// `mt_create` initiates a Merkle tree with a given initial hash `init`.
// A valid Merkle tree should contain at least one element.
val mt_create_custom:
hsz:hash_size_t ->
hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) ->
r:HST.erid -> init:hash #hsz -> hash_fun:hash_fun_t #hsz #hash_spec -> HST.ST mt_p
(requires (fun h0 ->
Rgl?.r_inv (hreg hsz) h0 init /\
HH.disjoint r (B.frameOf init)))
(ensures (fun h0 mt h1 ->
// memory safety
modifies (loc_union (mt_loc mt) (B.loc_all_regions_from false (B.frameOf init))) h0 h1 /\
mt_safe h1 mt /\
// correctness
MT?.hash_size (B.get h1 mt 0) = hsz /\
mt_lift h1 mt == MTH.mt_create (U32.v hsz) (Ghost.reveal hash_spec) (Rgl?.r_repr (hreg hsz) h0 init)))
#push-options "--z3rlimit 40"
let mt_create_custom hsz hash_spec r init hash_fun =
let hh0 = HST.get () in
let mt = create_empty_mt hsz hash_spec hash_fun r in
mt_insert hsz mt init;
let hh2 = HST.get () in
mt
#pop-options
/// Construction and Destruction of paths
// Since each element pointer in `path` is from the target Merkle tree and
// each element has different location in `MT?.hs` (thus different region id),
// we cannot use the regionality property for `path`s. Hence here we manually
// define invariants and representation.
noeq type path =
| Path: hash_size:hash_size_t ->
hashes:V.vector (hash #hash_size) ->
path
type path_p = B.pointer path
type const_path_p = const_pointer path
private
let phashes (h:HS.mem) (p:path_p)
: GTot (V.vector (hash #(Path?.hash_size (B.get h p 0))))
= Path?.hashes (B.get h p 0)
// Memory safety of a path as an invariant
inline_for_extraction noextract
val path_safe:
h:HS.mem -> mtr:HH.rid -> p:path_p -> GTot Type0
let path_safe h mtr p =
B.live h p /\ B.freeable p /\
V.live h (phashes h p) /\ V.freeable (phashes h p) /\
HST.is_eternal_region (V.frameOf (phashes h p)) /\
(let hsz = Path?.hash_size (B.get h p 0) in
V.forall_all h (phashes h p)
(fun hp -> Rgl?.r_inv (hreg hsz) h hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\
HH.extends (V.frameOf (phashes h p)) (B.frameOf p) /\
HH.disjoint mtr (B.frameOf p))
val path_loc: path_p -> GTot loc
let path_loc p = B.loc_all_regions_from false (B.frameOf p)
val lift_path_:
#hsz:hash_size_t ->
h:HS.mem ->
hs:S.seq (hash #hsz) ->
i:nat ->
j:nat{
i <= j /\ j <= S.length hs /\
V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)} ->
GTot (hp:MTH.path #(U32.v hsz) {S.length hp = j - i}) (decreases j)
let rec lift_path_ #hsz h hs i j =
if i = j then S.empty
else (S.snoc (lift_path_ h hs i (j - 1))
(Rgl?.r_repr (hreg hsz) h (S.index hs (j - 1))))
// Representation of a path
val lift_path:
#hsz:hash_size_t ->
h:HS.mem -> mtr:HH.rid -> p:path_p {path_safe h mtr p /\ (Path?.hash_size (B.get h p 0)) = hsz} ->
GTot (hp:MTH.path #(U32.v hsz) {S.length hp = U32.v (V.size_of (phashes h p))})
let lift_path #hsz h mtr p =
lift_path_ h (V.as_seq h (phashes h p))
0 (S.length (V.as_seq h (phashes h p)))
val lift_path_index_:
#hsz:hash_size_t ->
h:HS.mem ->
hs:S.seq (hash #hsz) ->
i:nat -> j:nat{i <= j && j <= S.length hs} ->
k:nat{i <= k && k < j} ->
Lemma (requires (V.forall_seq hs i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)))
(ensures (Rgl?.r_repr (hreg hsz) h (S.index hs k) ==
S.index (lift_path_ h hs i j) (k - i)))
(decreases j)
[SMTPat (S.index (lift_path_ h hs i j) (k - i))]
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lift_path_index_ #hsz h hs i j k =
if i = j then ()
else if k = j - 1 then ()
else lift_path_index_ #hsz h hs i (j - 1) k
#pop-options
val lift_path_index:
h:HS.mem -> mtr:HH.rid ->
p:path_p -> i:uint32_t ->
Lemma (requires (path_safe h mtr p /\
i < V.size_of (phashes h p)))
(ensures (let hsz = Path?.hash_size (B.get h p 0) in
Rgl?.r_repr (hreg hsz) h (V.get h (phashes h p) i) ==
S.index (lift_path #(hsz) h mtr p) (U32.v i)))
let lift_path_index h mtr p i =
lift_path_index_ h (V.as_seq h (phashes h p))
0 (S.length (V.as_seq h (phashes h p))) (U32.v i)
val lift_path_eq:
#hsz:hash_size_t ->
h:HS.mem ->
hs1:S.seq (hash #hsz) -> hs2:S.seq (hash #hsz) ->
i:nat -> j:nat ->
Lemma (requires (i <= j /\ j <= S.length hs1 /\ j <= S.length hs2 /\
S.equal (S.slice hs1 i j) (S.slice hs2 i j) /\
V.forall_seq hs1 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp) /\
V.forall_seq hs2 i j (fun hp -> Rgl?.r_inv (hreg hsz) h hp)))
(ensures (S.equal (lift_path_ h hs1 i j) (lift_path_ h hs2 i j)))
let lift_path_eq #hsz h hs1 hs2 i j =
assert (forall (k:nat{i <= k && k < j}).
S.index (lift_path_ h hs1 i j) (k - i) ==
Rgl?.r_repr (hreg hsz) h (S.index hs1 k));
assert (forall (k:nat{i <= k && k < j}).
S.index (lift_path_ h hs2 i j) (k - i) ==
Rgl?.r_repr (hreg hsz) h (S.index hs2 k));
assert (forall (k:nat{k < j - i}).
S.index (lift_path_ h hs1 i j) k ==
Rgl?.r_repr (hreg hsz) h (S.index hs1 (k + i)));
assert (forall (k:nat{k < j - i}).
S.index (lift_path_ h hs2 i j) k ==
Rgl?.r_repr (hreg hsz) h (S.index hs2 (k + i)));
assert (forall (k:nat{k < j - i}).
S.index (S.slice hs1 i j) k == S.index (S.slice hs2 i j) k);
assert (forall (k:nat{i <= k && k < j}).
S.index (S.slice hs1 i j) (k - i) == S.index (S.slice hs2 i j) (k - i))
private
val path_safe_preserved_:
#hsz:hash_size_t ->
mtr:HH.rid -> hs:S.seq (hash #hsz) ->
i:nat -> j:nat{i <= j && j <= S.length hs} ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma
(requires (V.forall_seq hs i j
(fun hp ->
Rgl?.r_inv (hreg hsz) h0 hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (V.forall_seq hs i j
(fun hp ->
Rgl?.r_inv (hreg hsz) h1 hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp))))
(decreases j)
let rec path_safe_preserved_ #hsz mtr hs i j dl h0 h1 =
if i = j then ()
else (assert (loc_includes
(B.loc_all_regions_from false mtr)
(B.loc_all_regions_from false
(Rgl?.region_of (hreg hsz) (S.index hs (j - 1)))));
Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1;
path_safe_preserved_ mtr hs i (j - 1) dl h0 h1)
val path_safe_preserved:
mtr:HH.rid -> p:path_p ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (path_safe h0 mtr p /\
loc_disjoint dl (path_loc p) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (path_safe h1 mtr p))
let path_safe_preserved mtr p dl h0 h1 =
assert (loc_includes (path_loc p) (B.loc_buffer p));
assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p)));
path_safe_preserved_
mtr (V.as_seq h0 (phashes h0 p))
0 (S.length (V.as_seq h0 (phashes h0 p))) dl h0 h1
val path_safe_init_preserved:
mtr:HH.rid -> p:path_p ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (path_safe h0 mtr p /\
V.size_of (phashes h0 p) = 0ul /\
B.loc_disjoint dl (path_loc p) /\
modifies dl h0 h1))
(ensures (path_safe h1 mtr p /\
V.size_of (phashes h1 p) = 0ul))
let path_safe_init_preserved mtr p dl h0 h1 =
assert (loc_includes (path_loc p) (B.loc_buffer p));
assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p)))
val path_preserved_:
#hsz:hash_size_t ->
mtr:HH.rid ->
hs:S.seq (hash #hsz) ->
i:nat -> j:nat{i <= j && j <= S.length hs} ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (V.forall_seq hs i j
(fun hp -> Rgl?.r_inv (hreg hsz) h0 hp /\
HH.includes mtr (Rgl?.region_of (hreg hsz) hp)) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (path_safe_preserved_ mtr hs i j dl h0 h1;
S.equal (lift_path_ h0 hs i j)
(lift_path_ h1 hs i j)))
(decreases j)
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec path_preserved_ #hsz mtr hs i j dl h0 h1 =
if i = j then ()
else (path_safe_preserved_ mtr hs i (j - 1) dl h0 h1;
path_preserved_ mtr hs i (j - 1) dl h0 h1;
assert (loc_includes
(B.loc_all_regions_from false mtr)
(B.loc_all_regions_from false
(Rgl?.region_of (hreg hsz) (S.index hs (j - 1)))));
Rgl?.r_sep (hreg hsz) (S.index hs (j - 1)) dl h0 h1)
#pop-options
val path_preserved:
mtr:HH.rid -> p:path_p ->
dl:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (path_safe h0 mtr p /\
loc_disjoint dl (path_loc p) /\
loc_disjoint dl (B.loc_all_regions_from false mtr) /\
modifies dl h0 h1))
(ensures (path_safe_preserved mtr p dl h0 h1;
let hsz0 = (Path?.hash_size (B.get h0 p 0)) in
let hsz1 = (Path?.hash_size (B.get h1 p 0)) in
let b:MTH.path = lift_path #hsz0 h0 mtr p in
let a:MTH.path = lift_path #hsz1 h1 mtr p in
hsz0 = hsz1 /\ S.equal b a))
let path_preserved mtr p dl h0 h1 =
assert (loc_includes (path_loc p) (B.loc_buffer p));
assert (loc_includes (path_loc p) (V.loc_vector (phashes h0 p)));
path_preserved_ mtr (V.as_seq h0 (phashes h0 p))
0 (S.length (V.as_seq h0 (phashes h0 p)))
dl h0 h1
val init_path:
hsz:hash_size_t ->
mtr:HH.rid -> r:HST.erid ->
HST.ST path_p
(requires (fun h0 -> HH.disjoint mtr r))
(ensures (fun h0 p h1 ->
// memory safety
path_safe h1 mtr p /\
// correctness
Path?.hash_size (B.get h1 p 0) = hsz /\
S.equal (lift_path #hsz h1 mtr p) S.empty))
let init_path hsz mtr r =
let nrid = HST.new_region r in
(B.malloc r (Path hsz (rg_alloc (hvreg hsz) nrid)) 1ul)
val clear_path:
mtr:HH.rid -> p:path_p ->
HST.ST unit
(requires (fun h0 -> path_safe h0 mtr p))
(ensures (fun h0 _ h1 ->
// memory safety
path_safe h1 mtr p /\
// correctness
V.size_of (phashes h1 p) = 0ul /\
S.equal (lift_path #(Path?.hash_size (B.get h1 p 0)) h1 mtr p) S.empty))
let clear_path mtr p =
let pv = !*p in
p *= Path (Path?.hash_size pv) (V.clear (Path?.hashes pv))
val free_path:
p:path_p ->
HST.ST unit
(requires (fun h0 ->
B.live h0 p /\ B.freeable p /\
V.live h0 (phashes h0 p) /\ V.freeable (phashes h0 p) /\
HH.extends (V.frameOf (phashes h0 p)) (B.frameOf p)))
(ensures (fun h0 _ h1 ->
modifies (path_loc p) h0 h1))
let free_path p =
let pv = !*p in
V.free (Path?.hashes pv);
B.free p
/// Getting the Merkle root and path
// Construct "rightmost hashes" for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
private
val construct_rhs:
#hsz:hash_size_t ->
#hash_spec:Ghost.erased (MTS.hash_fun_t #(U32.v hsz)) ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{i <= j && (U32.v j) < pow2 (32 - U32.v lv)} ->
acc:hash #hsz ->
actd:bool ->
hash_fun:hash_fun_t #hsz #(Ghost.reveal hash_spec) ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\
HH.disjoint (V.frameOf hs) (V.frameOf rhs) /\
Rgl?.r_inv (hreg hsz) h0 acc /\
HH.disjoint (B.frameOf acc) (V.frameOf hs) /\
HH.disjoint (B.frameOf acc) (V.frameOf rhs) /\
mt_safe_elts #hsz h0 lv hs i j))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf acc)))
h0 h1 /\
RV.rv_inv h1 rhs /\
Rgl?.r_inv (hreg hsz) h1 acc /\
// correctness
(mt_safe_elts_spec #hsz h0 lv hs i j;
MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec)
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) h0 hs)
(Rgl?.r_repr (hvreg hsz) h0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) h0 acc) actd ==
(Rgl?.r_repr (hvreg hsz) h1 rhs, Rgl?.r_repr (hreg hsz) h1 acc)
)))
(decreases (U32.v j))
#push-options "--z3rlimit 250 --initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec construct_rhs #hsz #hash_spec lv hs rhs i j acc actd hash_fun =
let hh0 = HST.get () in
if j = 0ul then begin
assert (RV.rv_inv hh0 hs);
assert (mt_safe_elts #hsz hh0 lv hs i j);
mt_safe_elts_spec #hsz hh0 lv hs 0ul 0ul;
assert (MTH.hs_wf_elts #(U32.v hsz)
(U32.v lv) (RV.as_seq hh0 hs)
(U32.v i) (U32.v j));
let hh1 = HST.get() in
assert (MTH.construct_rhs #(U32.v hsz) #(Ghost.reveal hash_spec)
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 acc) actd ==
(Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc))
end
else
let ofs = offset_of i in
begin
(if j % 2ul = 0ul
then begin
Math.Lemmas.pow2_double_mult (32 - U32.v lv - 1);
mt_safe_elts_rec #hsz hh0 lv hs i j;
construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc actd hash_fun;
let hh1 = HST.get () in
// correctness
mt_safe_elts_spec #hsz hh0 lv hs i j;
MTH.construct_rhs_even #(U32.v hsz) #hash_spec
(U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd;
assert (MTH.construct_rhs #(U32.v hsz) #hash_spec
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 acc)
actd ==
(Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 acc))
end
else begin
if actd
then begin
RV.assign_copy (hcpy hsz) rhs lv acc;
let hh1 = HST.get () in
// memory safety
Rgl?.r_sep (hreg hsz) acc
(B.loc_all_regions_from false (V.frameOf rhs)) hh0 hh1;
RV.rv_inv_preserved
hs (B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
RV.as_seq_preserved
hs (B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
RV.rv_inv_preserved
(V.get hh0 hs lv) (B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
V.loc_vector_within_included hs lv (V.size_of hs);
mt_safe_elts_preserved lv hs i j
(B.loc_all_regions_from false (V.frameOf rhs))
hh0 hh1;
mt_safe_elts_head hh1 lv hs i j;
hash_vv_rv_inv_r_inv hh1 hs lv (j - 1ul - ofs);
// correctness
assert (S.equal (RV.as_seq hh1 rhs)
(S.upd (RV.as_seq hh0 rhs) (U32.v lv)
(Rgl?.r_repr (hreg hsz) hh0 acc)));
hash_fun (V.index (V.index hs lv) (j - 1ul - ofs)) acc acc;
let hh2 = HST.get () in
// memory safety
mt_safe_elts_preserved lv hs i j
(B.loc_all_regions_from false (B.frameOf acc)) hh1 hh2;
RV.rv_inv_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.rv_inv_preserved
rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.as_seq_preserved
hs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
RV.as_seq_preserved
rhs (B.loc_region_only false (B.frameOf acc)) hh1 hh2;
// correctness
hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs);
assert (Rgl?.r_repr (hreg hsz) hh2 acc ==
(Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs))
(Rgl?.r_repr (hreg hsz) hh0 acc))
end
else begin
mt_safe_elts_head hh0 lv hs i j;
hash_vv_rv_inv_r_inv hh0 hs lv (j - 1ul - ofs);
hash_vv_rv_inv_disjoint hh0 hs lv (j - 1ul - ofs) (B.frameOf acc);
Cpy?.copy (hcpy hsz) hsz (V.index (V.index hs lv) (j - 1ul - ofs)) acc;
let hh1 = HST.get () in
// memory safety
V.loc_vector_within_included hs lv (V.size_of hs);
mt_safe_elts_preserved lv hs i j
(B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.rv_inv_preserved
hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.rv_inv_preserved
rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.as_seq_preserved
hs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
RV.as_seq_preserved
rhs (B.loc_all_regions_from false (B.frameOf acc)) hh0 hh1;
// correctness
hash_vv_as_seq_get_index hh0 hs lv (j - 1ul - ofs);
assert (Rgl?.r_repr (hreg hsz) hh1 acc ==
S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs))
end;
let hh3 = HST.get () in
assert (S.equal (RV.as_seq hh3 hs) (RV.as_seq hh0 hs));
assert (S.equal (RV.as_seq hh3 rhs)
(if actd
then S.upd (RV.as_seq hh0 rhs) (U32.v lv)
(Rgl?.r_repr (hreg hsz) hh0 acc)
else RV.as_seq hh0 rhs));
assert (Rgl?.r_repr (hreg hsz) hh3 acc ==
(if actd
then (Ghost.reveal hash_spec) (S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs))
(Rgl?.r_repr (hreg hsz) hh0 acc)
else S.index (S.index (RV.as_seq hh0 hs) (U32.v lv))
(U32.v j - 1 - U32.v ofs)));
mt_safe_elts_rec hh3 lv hs i j;
construct_rhs #hsz #hash_spec (lv + 1ul) hs rhs (i / 2ul) (j / 2ul) acc true hash_fun;
let hh4 = HST.get () in
mt_safe_elts_spec hh3 (lv + 1ul) hs (i / 2ul) (j / 2ul);
assert (MTH.construct_rhs #(U32.v hsz) #hash_spec
(U32.v lv + 1)
(Rgl?.r_repr (hvvreg hsz) hh3 hs)
(Rgl?.r_repr (hvreg hsz) hh3 rhs)
(U32.v i / 2) (U32.v j / 2)
(Rgl?.r_repr (hreg hsz) hh3 acc) true ==
(Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc));
mt_safe_elts_spec hh0 lv hs i j;
MTH.construct_rhs_odd #(U32.v hsz) #hash_spec
(U32.v lv) (Rgl?.r_repr (hvvreg hsz) hh0 hs) (Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j) (Rgl?.r_repr (hreg hsz) hh0 acc) actd;
assert (MTH.construct_rhs #(U32.v hsz) #hash_spec
(U32.v lv)
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 acc) actd ==
(Rgl?.r_repr (hvreg hsz) hh4 rhs, Rgl?.r_repr (hreg hsz) hh4 acc))
end)
end
#pop-options
private inline_for_extraction
val mt_get_root_pre_nst: mtv:merkle_tree -> rt:hash #(MT?.hash_size mtv) -> Tot bool
let mt_get_root_pre_nst mtv rt = true
val mt_get_root_pre:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
rt:hash #hsz ->
HST.ST bool
(requires (fun h0 ->
let mt = CB.cast mt in
MT?.hash_size (B.get h0 mt 0) = Ghost.reveal hsz /\
mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\
HH.disjoint (B.frameOf mt) (B.frameOf rt)))
(ensures (fun _ _ _ -> True))
let mt_get_root_pre #hsz mt rt =
let mt = CB.cast mt in
let mt = !*mt in
let hsz = MT?.hash_size mt in
assert (MT?.hash_size mt = hsz);
mt_get_root_pre_nst mt rt
// `mt_get_root` returns the Merkle root. If it's already calculated with
// up-to-date hashes, the root is returned immediately. Otherwise it calls
// `construct_rhs` to build rightmost hashes and to calculate the Merkle root
// as well.
val mt_get_root:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
rt:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
let mt = CB.cast mt in
let dmt = B.get h0 mt 0 in
MT?.hash_size dmt = (Ghost.reveal hsz) /\
mt_get_root_pre_nst dmt rt /\
mt_safe h0 mt /\ Rgl?.r_inv (hreg hsz) h0 rt /\
HH.disjoint (B.frameOf mt) (B.frameOf rt)))
(ensures (fun h0 _ h1 ->
let mt = CB.cast mt in
// memory safety
modifies (loc_union
(mt_loc mt)
(B.loc_all_regions_from false (B.frameOf rt)))
h0 h1 /\
mt_safe h1 mt /\
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
MT?.hash_size mtv0 = (Ghost.reveal hsz) /\
MT?.hash_size mtv1 = (Ghost.reveal hsz) /\
MT?.i mtv1 = MT?.i mtv0 /\ MT?.j mtv1 = MT?.j mtv0 /\
MT?.hs mtv1 == MT?.hs mtv0 /\ MT?.rhs mtv1 == MT?.rhs mtv0 /\
MT?.offset mtv1 == MT?.offset mtv0 /\
MT?.rhs_ok mtv1 = true /\
Rgl?.r_inv (hreg hsz) h1 rt /\
// correctness
MTH.mt_get_root (mt_lift h0 mt) (Rgl?.r_repr (hreg hsz) h0 rt) ==
(mt_lift h1 mt, Rgl?.r_repr (hreg hsz) h1 rt))))
#push-options "--z3rlimit 150 --initial_fuel 1 --max_fuel 1"
let mt_get_root #hsz mt rt =
let mt = CB.cast mt in
let hh0 = HST.get () in
let mtv = !*mt in
let prefix = MT?.offset mtv in
let i = MT?.i mtv in
let j = MT?.j mtv in
let hs = MT?.hs mtv in
let rhs = MT?.rhs mtv in
let mroot = MT?.mroot mtv in
let hash_size = MT?.hash_size mtv in
let hash_spec = MT?.hash_spec mtv in
let hash_fun = MT?.hash_fun mtv in
if MT?.rhs_ok mtv
then begin
Cpy?.copy (hcpy hash_size) hash_size mroot rt;
let hh1 = HST.get () in
mt_safe_preserved mt
(B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1;
mt_preserved mt
(B.loc_all_regions_from false (Rgl?.region_of (hreg hsz) rt)) hh0 hh1;
MTH.mt_get_root_rhs_ok_true
(mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt);
assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) ==
(mt_lift hh1 mt, Rgl?.r_repr (hreg hsz) hh1 rt))
end
else begin
construct_rhs #hash_size #hash_spec 0ul hs rhs i j rt false hash_fun;
let hh1 = HST.get () in
// memory safety
assert (RV.rv_inv hh1 rhs);
assert (Rgl?.r_inv (hreg hsz) hh1 rt);
assert (B.live hh1 mt);
RV.rv_inv_preserved
hs (loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf rt)))
hh0 hh1;
RV.as_seq_preserved
hs (loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf rt)))
hh0 hh1;
V.loc_vector_within_included hs 0ul (V.size_of hs);
mt_safe_elts_preserved 0ul hs i j
(loc_union
(RV.loc_rvector rhs)
(B.loc_all_regions_from false (B.frameOf rt)))
hh0 hh1;
// correctness
mt_safe_elts_spec hh0 0ul hs i j;
assert (MTH.construct_rhs #(U32.v hash_size) #hash_spec 0
(Rgl?.r_repr (hvvreg hsz) hh0 hs)
(Rgl?.r_repr (hvreg hsz) hh0 rhs)
(U32.v i) (U32.v j)
(Rgl?.r_repr (hreg hsz) hh0 rt) false ==
(Rgl?.r_repr (hvreg hsz) hh1 rhs, Rgl?.r_repr (hreg hsz) hh1 rt));
Cpy?.copy (hcpy hash_size) hash_size rt mroot;
let hh2 = HST.get () in
// memory safety
RV.rv_inv_preserved
hs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
RV.rv_inv_preserved
rhs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
RV.as_seq_preserved
hs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
RV.as_seq_preserved
rhs (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
B.modifies_buffer_elim
rt (B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
mt_safe_elts_preserved 0ul hs i j
(B.loc_all_regions_from false (B.frameOf mroot))
hh1 hh2;
// correctness
assert (Rgl?.r_repr (hreg hsz) hh2 mroot == Rgl?.r_repr (hreg hsz) hh1 rt);
mt *= MT hash_size prefix i j hs true rhs mroot hash_spec hash_fun;
let hh3 = HST.get () in
// memory safety
Rgl?.r_sep (hreg hsz) rt (B.loc_buffer mt) hh2 hh3;
RV.rv_inv_preserved hs (B.loc_buffer mt) hh2 hh3;
RV.rv_inv_preserved rhs (B.loc_buffer mt) hh2 hh3;
RV.as_seq_preserved hs (B.loc_buffer mt) hh2 hh3;
RV.as_seq_preserved rhs (B.loc_buffer mt) hh2 hh3;
Rgl?.r_sep (hreg hsz) mroot (B.loc_buffer mt) hh2 hh3;
mt_safe_elts_preserved 0ul hs i j
(B.loc_buffer mt) hh2 hh3;
assert (mt_safe hh3 mt);
// correctness
MTH.mt_get_root_rhs_ok_false
(mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt);
assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) ==
(MTH.MT #(U32.v hash_size)
(U32.v i) (U32.v j)
(RV.as_seq hh0 hs)
true
(RV.as_seq hh1 rhs)
(Rgl?.r_repr (hreg hsz) hh1 rt)
hash_spec,
Rgl?.r_repr (hreg hsz) hh1 rt));
assert (MTH.mt_get_root (mt_lift hh0 mt) (Rgl?.r_repr (hreg hsz) hh0 rt) ==
(mt_lift hh3 mt, Rgl?.r_repr (hreg hsz) hh3 rt))
end
#pop-options
inline_for_extraction
val mt_path_insert:
#hsz:hash_size_t ->
mtr:HH.rid -> p:path_p -> hp:hash #hsz ->
HST.ST unit
(requires (fun h0 ->
path_safe h0 mtr p /\
not (V.is_full (phashes h0 p)) /\
Rgl?.r_inv (hreg hsz) h0 hp /\
HH.disjoint mtr (B.frameOf p) /\
HH.includes mtr (B.frameOf hp) /\
Path?.hash_size (B.get h0 p 0) = hsz))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (path_loc p) h0 h1 /\
path_safe h1 mtr p /\
// correctness
(let hsz0 = Path?.hash_size (B.get h0 p 0) in
let hsz1 = Path?.hash_size (B.get h1 p 0) in
(let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in
let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in
V.size_of (phashes h1 p) = V.size_of (phashes h0 p) + 1ul /\
hsz = hsz0 /\ hsz = hsz1 /\
(let hspec:(S.seq (MTH.hash #(U32.v hsz))) = (MTH.path_insert #(U32.v hsz) before (Rgl?.r_repr (hreg hsz) h0 hp)) in
S.equal hspec after)))))
#push-options "--z3rlimit 20 --initial_fuel 1 --max_fuel 1"
let mt_path_insert #hsz mtr p hp =
let pth = !*p in
let pv = Path?.hashes pth in
let hh0 = HST.get () in
let ipv = V.insert pv hp in
let hh1 = HST.get () in
path_safe_preserved_
mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv))
(B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1;
path_preserved_
mtr (V.as_seq hh0 pv) 0 (S.length (V.as_seq hh0 pv))
(B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1;
Rgl?.r_sep (hreg hsz) hp
(B.loc_all_regions_from false (V.frameOf ipv)) hh0 hh1;
p *= Path hsz ipv;
let hh2 = HST.get () in
path_safe_preserved_
mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv))
(B.loc_region_only false (B.frameOf p)) hh1 hh2;
path_preserved_
mtr (V.as_seq hh1 ipv) 0 (S.length (V.as_seq hh1 ipv))
(B.loc_region_only false (B.frameOf p)) hh1 hh2;
Rgl?.r_sep (hreg hsz) hp
(B.loc_region_only false (B.frameOf p)) hh1 hh2;
assert (S.equal (lift_path hh2 mtr p)
(lift_path_ hh1 (S.snoc (V.as_seq hh0 pv) hp)
0 (S.length (V.as_seq hh1 ipv))));
lift_path_eq hh1 (S.snoc (V.as_seq hh0 pv) hp) (V.as_seq hh0 pv)
0 (S.length (V.as_seq hh0 pv))
#pop-options
// For given a target index `k`, the number of elements (in the tree) `j`,
// and a boolean flag (to check the existence of rightmost hashes), we can
// calculate a required Merkle path length.
//
// `mt_path_length` is a postcondition of `mt_get_path`, and a precondition
// of `mt_verify`. For detailed description, see `mt_get_path` and `mt_verify`.
private
val mt_path_length_step:
k:index_t ->
j:index_t{k <= j} ->
actd:bool ->
Tot (sl:uint32_t{U32.v sl = MTH.mt_path_length_step (U32.v k) (U32.v j) actd})
let mt_path_length_step k j actd =
if j = 0ul then 0ul
else (if k % 2ul = 0ul
then (if j = k || (j = k + 1ul && not actd) then 0ul else 1ul)
else 1ul)
private inline_for_extraction
val mt_path_length:
lv:uint32_t{lv <= merkle_tree_size_lg} ->
k:index_t ->
j:index_t{k <= j && U32.v j < pow2 (32 - U32.v lv)} ->
actd:bool ->
Tot (l:uint32_t{
U32.v l = MTH.mt_path_length (U32.v k) (U32.v j) actd &&
l <= 32ul - lv})
(decreases (U32.v j))
#push-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1"
let rec mt_path_length lv k j actd =
if j = 0ul then 0ul
else (let nactd = actd || (j % 2ul = 1ul) in
mt_path_length_step k j actd +
mt_path_length (lv + 1ul) (k / 2ul) (j / 2ul) nactd)
#pop-options
val mt_get_path_length:
mtr:HH.rid ->
p:const_path_p ->
HST.ST uint32_t
(requires (fun h0 -> path_safe h0 mtr (CB.cast p)))
(ensures (fun h0 _ h1 -> True))
let mt_get_path_length mtr p =
let pd = !*(CB.cast p) in
V.size_of (Path?.hashes pd)
private inline_for_extraction
val mt_make_path_step:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
mtr:HH.rid ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} ->
i:index_t ->
j:index_t{j <> 0ul /\ i <= j /\ U32.v j < pow2 (32 - U32.v lv)} ->
k:index_t{i <= k && k <= j} ->
p:path_p ->
actd:bool ->
HST.ST unit
(requires (fun h0 ->
HH.includes mtr (V.frameOf hs) /\
HH.includes mtr (V.frameOf rhs) /\
RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\
mt_safe_elts h0 lv hs i j /\
path_safe h0 mtr p /\
Path?.hash_size (B.get h0 p 0) = hsz /\
V.size_of (phashes h0 p) <= lv + 1ul))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (path_loc p) h0 h1 /\
path_safe h1 mtr p /\
V.size_of (phashes h1 p) == V.size_of (phashes h0 p) + mt_path_length_step k j actd /\
V.size_of (phashes h1 p) <= lv + 2ul /\
// correctness
(mt_safe_elts_spec h0 lv hs i j;
(let hsz0 = Path?.hash_size (B.get h0 p 0) in
let hsz1 = Path?.hash_size (B.get h1 p 0) in
let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in
let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in
hsz = hsz0 /\ hsz = hsz1 /\
S.equal after
(MTH.mt_make_path_step
(U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs)
(U32.v i) (U32.v j) (U32.v k) before actd)))))
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let mt_make_path_step #hsz lv mtr hs rhs i j k p actd =
let pth = !*p in
let hh0 = HST.get () in
let ofs = offset_of i in
if k % 2ul = 1ul
then begin
hash_vv_rv_inv_includes hh0 hs lv (k - 1ul - ofs);
assert (HH.includes mtr
(B.frameOf (V.get hh0 (V.get hh0 hs lv) (k - 1ul - ofs))));
assert(Path?.hash_size pth = hsz);
mt_path_insert #hsz mtr p (V.index (V.index hs lv) (k - 1ul - ofs))
end
else begin
if k = j then ()
else if k + 1ul = j
then (if actd
then (assert (HH.includes mtr (B.frameOf (V.get hh0 rhs lv)));
mt_path_insert mtr p (V.index rhs lv)))
else (hash_vv_rv_inv_includes hh0 hs lv (k + 1ul - ofs);
assert (HH.includes mtr
(B.frameOf (V.get hh0 (V.get hh0 hs lv) (k + 1ul - ofs))));
mt_path_insert mtr p (V.index (V.index hs lv) (k + 1ul - ofs)))
end
#pop-options
private inline_for_extraction
val mt_get_path_step_pre_nst:
#hsz:Ghost.erased hash_size_t ->
mtr:HH.rid ->
p:path ->
i:uint32_t ->
Tot bool
let mt_get_path_step_pre_nst #hsz mtr p i =
i < V.size_of (Path?.hashes p)
val mt_get_path_step_pre:
#hsz:Ghost.erased hash_size_t ->
mtr:HH.rid ->
p:const_path_p ->
i:uint32_t ->
HST.ST bool
(requires (fun h0 ->
path_safe h0 mtr (CB.cast p) /\
(let pv = B.get h0 (CB.cast p) 0 in
Path?.hash_size pv = Ghost.reveal hsz /\
live h0 (Path?.hashes pv) /\
mt_get_path_step_pre_nst #hsz mtr pv i)))
(ensures (fun _ _ _ -> True))
let mt_get_path_step_pre #hsz mtr p i =
let p = CB.cast p in
mt_get_path_step_pre_nst #hsz mtr !*p i
val mt_get_path_step:
#hsz:Ghost.erased hash_size_t ->
mtr:HH.rid ->
p:const_path_p ->
i:uint32_t ->
HST.ST (hash #hsz)
(requires (fun h0 ->
path_safe h0 mtr (CB.cast p) /\
(let pv = B.get h0 (CB.cast p) 0 in
Path?.hash_size pv = Ghost.reveal hsz /\
live h0 (Path?.hashes pv) /\
i < V.size_of (Path?.hashes pv))))
(ensures (fun h0 r h1 -> True ))
let mt_get_path_step #hsz mtr p i =
let pd = !*(CB.cast p) in
V.index #(hash #(Path?.hash_size pd)) (Path?.hashes pd) i
private
val mt_get_path_:
#hsz:hash_size_t ->
lv:uint32_t{lv <= merkle_tree_size_lg} ->
mtr:HH.rid ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
rhs:hash_vec #hsz {V.size_of rhs = merkle_tree_size_lg} ->
i:index_t -> j:index_t{i <= j /\ U32.v j < pow2 (32 - U32.v lv)} ->
k:index_t{i <= k && k <= j} ->
p:path_p ->
actd:bool ->
HST.ST unit
(requires (fun h0 ->
HH.includes mtr (V.frameOf hs) /\
HH.includes mtr (V.frameOf rhs) /\
RV.rv_inv h0 hs /\ RV.rv_inv h0 rhs /\
mt_safe_elts h0 lv hs i j /\
path_safe h0 mtr p /\
Path?.hash_size (B.get h0 p 0) = hsz /\
V.size_of (phashes h0 p) <= lv + 1ul))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (path_loc p) h0 h1 /\
path_safe h1 mtr p /\
V.size_of (phashes h1 p) ==
V.size_of (phashes h0 p) + mt_path_length lv k j actd /\
// correctness
(mt_safe_elts_spec h0 lv hs i j;
(let hsz0 = Path?.hash_size (B.get h0 p 0) in
let hsz1 = Path?.hash_size (B.get h1 p 0) in
let before:(S.seq (MTH.hash #(U32.v hsz0))) = lift_path h0 mtr p in
let after:(S.seq (MTH.hash #(U32.v hsz1))) = lift_path h1 mtr p in
hsz = hsz0 /\ hsz = hsz1 /\
S.equal after
(MTH.mt_get_path_ (U32.v lv) (RV.as_seq h0 hs) (RV.as_seq h0 rhs)
(U32.v i) (U32.v j) (U32.v k) before actd)))))
(decreases (32 - U32.v lv))
#push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1 --max_ifuel 2 --initial_ifuel 2"
let rec mt_get_path_ #hsz lv mtr hs rhs i j k p actd =
let hh0 = HST.get () in
mt_safe_elts_spec hh0 lv hs i j;
let ofs = offset_of i in
if j = 0ul then ()
else
(mt_make_path_step lv mtr hs rhs i j k p actd;
let hh1 = HST.get () in
mt_safe_elts_spec hh0 lv hs i j;
assert (S.equal (lift_path hh1 mtr p)
(MTH.mt_make_path_step
(U32.v lv) (RV.as_seq hh0 hs) (RV.as_seq hh0 rhs)
(U32.v i) (U32.v j) (U32.v k)
(lift_path hh0 mtr p) actd));
RV.rv_inv_preserved hs (path_loc p) hh0 hh1;
RV.rv_inv_preserved rhs (path_loc p) hh0 hh1;
RV.as_seq_preserved hs (path_loc p) hh0 hh1;
RV.as_seq_preserved rhs (path_loc p) hh0 hh1;
V.loc_vector_within_included hs lv (V.size_of hs);
mt_safe_elts_preserved lv hs i j (path_loc p) hh0 hh1;
assert (mt_safe_elts hh1 lv hs i j);
mt_safe_elts_rec hh1 lv hs i j;
mt_safe_elts_spec hh1 (lv + 1ul) hs (i / 2ul) (j / 2ul);
mt_get_path_ (lv + 1ul) mtr hs rhs (i / 2ul) (j / 2ul) (k / 2ul) p
(if j % 2ul = 0ul then actd else true);
let hh2 = HST.get () in
assert (S.equal (lift_path hh2 mtr p)
(MTH.mt_get_path_ (U32.v lv + 1)
(RV.as_seq hh1 hs) (RV.as_seq hh1 rhs)
(U32.v i / 2) (U32.v j / 2) (U32.v k / 2)
(lift_path hh1 mtr p)
(if U32.v j % 2 = 0 then actd else true)));
assert (S.equal (lift_path hh2 mtr p)
(MTH.mt_get_path_ (U32.v lv)
(RV.as_seq hh0 hs) (RV.as_seq hh0 rhs)
(U32.v i) (U32.v j) (U32.v k)
(lift_path hh0 mtr p) actd)))
#pop-options
private inline_for_extraction
val mt_get_path_pre_nst:
mtv:merkle_tree ->
idx:offset_t ->
p:path ->
root:(hash #(MT?.hash_size mtv)) ->
Tot bool
let mt_get_path_pre_nst mtv idx p root =
offsets_connect (MT?.offset mtv) idx &&
Path?.hash_size p = MT?.hash_size mtv &&
([@inline_let] let idx = split_offset (MT?.offset mtv) idx in
MT?.i mtv <= idx && idx < MT?.j mtv &&
V.size_of (Path?.hashes p) = 0ul)
val mt_get_path_pre:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
idx:offset_t ->
p:const_path_p ->
root:hash #hsz ->
HST.ST bool
(requires (fun h0 ->
let mt = CB.cast mt in
let p = CB.cast p in
let dmt = B.get h0 mt 0 in
let dp = B.get h0 p 0 in
MT?.hash_size dmt = (Ghost.reveal hsz) /\
Path?.hash_size dp = (Ghost.reveal hsz) /\
mt_safe h0 mt /\
path_safe h0 (B.frameOf mt) p /\
Rgl?.r_inv (hreg hsz) h0 root /\
HH.disjoint (B.frameOf root) (B.frameOf mt) /\
HH.disjoint (B.frameOf root) (B.frameOf p)))
(ensures (fun _ _ _ -> True))
let mt_get_path_pre #_ mt idx p root =
let mt = CB.cast mt in
let p = CB.cast p in
let mtv = !*mt in
mt_get_path_pre_nst mtv idx !*p root
val mt_get_path_loc_union_helper:
l1:loc -> l2:loc ->
Lemma (loc_union (loc_union l1 l2) l2 == loc_union l1 l2)
let mt_get_path_loc_union_helper l1 l2 = ()
// Construct a Merkle path for a given index `idx`, hashes `mt.hs`, and rightmost
// hashes `mt.rhs`. Note that this operation copies "pointers" into the Merkle tree
// to the output path.
#push-options "--z3rlimit 60"
val mt_get_path:
#hsz:Ghost.erased hash_size_t ->
mt:const_mt_p ->
idx:offset_t ->
p:path_p ->
root:hash #hsz ->
HST.ST index_t
(requires (fun h0 ->
let mt = CB.cast mt in
let dmt = B.get h0 mt 0 in
MT?.hash_size dmt = Ghost.reveal hsz /\
Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\
mt_get_path_pre_nst (B.get h0 mt 0) idx (B.get h0 p 0) root /\
mt_safe h0 mt /\
path_safe h0 (B.frameOf mt) p /\
Rgl?.r_inv (hreg hsz) h0 root /\
HH.disjoint (B.frameOf root) (B.frameOf mt) /\
HH.disjoint (B.frameOf root) (B.frameOf p)))
(ensures (fun h0 _ h1 ->
let mt = CB.cast mt in
let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let idx = split_offset (MT?.offset mtv0) idx in
MT?.hash_size mtv0 = Ghost.reveal hsz /\
MT?.hash_size mtv1 = Ghost.reveal hsz /\
Path?.hash_size (B.get h0 p 0) = Ghost.reveal hsz /\
Path?.hash_size (B.get h1 p 0) = Ghost.reveal hsz /\
// memory safety
modifies (loc_union
(loc_union
(mt_loc mt)
(B.loc_all_regions_from false (B.frameOf root)))
(path_loc p))
h0 h1 /\
mt_safe h1 mt /\
path_safe h1 (B.frameOf mt) p /\
Rgl?.r_inv (hreg hsz) h1 root /\
V.size_of (phashes h1 p) ==
1ul + mt_path_length 0ul idx (MT?.j mtv0) false /\
// correctness
(let sj, sp, srt =
MTH.mt_get_path
(mt_lift h0 mt) (U32.v idx) (Rgl?.r_repr (hreg hsz) h0 root) in
sj == U32.v (MT?.j mtv1) /\
S.equal sp (lift_path #hsz h1 (B.frameOf mt) p) /\
srt == Rgl?.r_repr (hreg hsz) h1 root)))
#pop-options
#push-options "--z3rlimit 300 --initial_fuel 1 --max_fuel 1"
let mt_get_path #hsz mt idx p root =
let ncmt = CB.cast mt in
let mtframe = B.frameOf ncmt in
let hh0 = HST.get () in
mt_get_root mt root;
let mtv = !*ncmt in
let hsz = MT?.hash_size mtv in
let hh1 = HST.get () in
path_safe_init_preserved mtframe p
(B.loc_union (mt_loc ncmt)
(B.loc_all_regions_from false (B.frameOf root)))
hh0 hh1;
assert (MTH.mt_get_root (mt_lift hh0 ncmt) (Rgl?.r_repr (hreg hsz) hh0 root) ==
(mt_lift hh1 ncmt, Rgl?.r_repr (hreg hsz) hh1 root));
assert (S.equal (lift_path #hsz hh1 mtframe p) S.empty);
let idx = split_offset (MT?.offset mtv) idx in
let i = MT?.i mtv in
let ofs = offset_of (MT?.i mtv) in
let j = MT?.j mtv in
let hs = MT?.hs mtv in
let rhs = MT?.rhs mtv in
assert (mt_safe_elts hh1 0ul hs i j);
assert (V.size_of (V.get hh1 hs 0ul) == j - ofs);
assert (idx < j);
hash_vv_rv_inv_includes hh1 hs 0ul (idx - ofs);
hash_vv_rv_inv_r_inv hh1 hs 0ul (idx - ofs);
hash_vv_as_seq_get_index hh1 hs 0ul (idx - ofs);
let ih = V.index (V.index hs 0ul) (idx - ofs) in
mt_path_insert #hsz mtframe p ih;
let hh2 = HST.get () in
assert (S.equal (lift_path hh2 mtframe p)
(MTH.path_insert
(lift_path hh1 mtframe p)
(S.index (S.index (RV.as_seq hh1 hs) 0) (U32.v idx - U32.v ofs))));
Rgl?.r_sep (hreg hsz) root (path_loc p) hh1 hh2;
mt_safe_preserved ncmt (path_loc p) hh1 hh2;
mt_preserved ncmt (path_loc p) hh1 hh2;
assert (V.size_of (phashes hh2 p) == 1ul);
mt_get_path_ 0ul mtframe hs rhs i j idx p false;
let hh3 = HST.get () in
// memory safety
mt_get_path_loc_union_helper
(loc_union (mt_loc ncmt)
(B.loc_all_regions_from false (B.frameOf root)))
(path_loc p);
Rgl?.r_sep (hreg hsz) root (path_loc p) hh2 hh3;
mt_safe_preserved ncmt (path_loc p) hh2 hh3;
mt_preserved ncmt (path_loc p) hh2 hh3;
assert (V.size_of (phashes hh3 p) ==
1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false);
assert (S.length (lift_path #hsz hh3 mtframe p) ==
S.length (lift_path #hsz hh2 mtframe p) +
MTH.mt_path_length (U32.v idx) (U32.v (MT?.j (B.get hh0 ncmt 0))) false);
assert (modifies (loc_union
(loc_union
(mt_loc ncmt)
(B.loc_all_regions_from false (B.frameOf root)))
(path_loc p))
hh0 hh3);
assert (mt_safe hh3 ncmt);
assert (path_safe hh3 mtframe p);
assert (Rgl?.r_inv (hreg hsz) hh3 root);
assert (V.size_of (phashes hh3 p) ==
1ul + mt_path_length 0ul idx (MT?.j (B.get hh0 ncmt 0)) false);
// correctness
mt_safe_elts_spec hh2 0ul hs i j;
assert (S.equal (lift_path hh3 mtframe p)
(MTH.mt_get_path_ 0 (RV.as_seq hh2 hs) (RV.as_seq hh2 rhs)
(U32.v i) (U32.v j) (U32.v idx)
(lift_path hh2 mtframe p) false));
assert (MTH.mt_get_path
(mt_lift hh0 ncmt) (U32.v idx) (Rgl?.r_repr (hreg hsz) hh0 root) ==
(U32.v (MT?.j (B.get hh3 ncmt 0)),
lift_path hh3 mtframe p,
Rgl?.r_repr (hreg hsz) hh3 root));
j
#pop-options
/// Flushing
private val
mt_flush_to_modifies_rec_helper:
#hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
h:HS.mem ->
Lemma (loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))) ==
loc_union
(RV.rv_loc_elems h hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
#push-options "--initial_fuel 2 --max_fuel 2"
let mt_flush_to_modifies_rec_helper #hsz lv hs h =
assert (V.loc_vector_within hs lv (V.size_of hs) ==
loc_union (V.loc_vector_within hs lv (lv + 1ul))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)));
RV.rs_loc_elems_rec_inverse (hvreg hsz) (V.as_seq h hs) (U32.v lv) (U32.v (V.size_of hs));
assert (RV.rv_loc_elems h hs lv (V.size_of hs) ==
loc_union (RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs)));
loc_union_assoc_4
(RV.rs_loc_elem (hvreg hsz) (V.as_seq h hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems h hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))
#pop-options
private
val mt_flush_to_:
hsz:hash_size_t ->
lv:uint32_t{lv < merkle_tree_size_lg} ->
hs:hash_vv hsz {V.size_of hs = merkle_tree_size_lg} ->
pi:index_t ->
i:index_t{i >= pi} ->
j:Ghost.erased index_t{
Ghost.reveal j >= i &&
U32.v (Ghost.reveal j) < pow2 (32 - U32.v lv)} ->
HST.ST unit
(requires (fun h0 ->
RV.rv_inv h0 hs /\
mt_safe_elts h0 lv hs pi (Ghost.reveal j)))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (loc_union
(RV.rv_loc_elems h0 hs lv (V.size_of hs))
(V.loc_vector_within hs lv (V.size_of hs)))
h0 h1 /\
RV.rv_inv h1 hs /\
mt_safe_elts h1 lv hs i (Ghost.reveal j) /\
// correctness
(mt_safe_elts_spec h0 lv hs pi (Ghost.reveal j);
S.equal (RV.as_seq h1 hs)
(MTH.mt_flush_to_
(U32.v lv) (RV.as_seq h0 hs) (U32.v pi)
(U32.v i) (U32.v (Ghost.reveal j))))))
(decreases (U32.v i))
#restart-solver
#push-options "--z3rlimit 1500 --fuel 1 --ifuel 0"
let rec mt_flush_to_ hsz lv hs pi i j =
let hh0 = HST.get () in
// Base conditions
mt_safe_elts_rec hh0 lv hs pi (Ghost.reveal j);
V.loc_vector_within_included hs 0ul lv;
V.loc_vector_within_included hs lv (lv + 1ul);
V.loc_vector_within_included hs (lv + 1ul) (V.size_of hs);
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j)
else begin
/// 1) Flush hashes at the level `lv`, where the new vector is
/// not yet connected to `hs`.
let ofs = oi - opi in
let hvec = V.index hs lv in
let flushed:(rvector (hreg hsz)) = rv_flush_inplace hvec ofs in
let hh1 = HST.get () in
// 1-0) Basic disjointness conditions for `RV.assign`
V.forall2_forall_left hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall2_forall_right hh0 hs 0ul (V.size_of hs) lv
(fun b1 b2 -> HH.disjoint (Rgl?.region_of (hvreg hsz) b1)
(Rgl?.region_of (hvreg hsz) b2));
V.forall_preserved
hs 0ul lv
(fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec)
(Rgl?.region_of (hvreg hsz) b))
(RV.loc_rvector hvec)
hh0 hh1;
V.forall_preserved
hs (lv + 1ul) (V.size_of hs)
(fun b -> HH.disjoint (Rgl?.region_of (hvreg hsz) hvec)
(Rgl?.region_of (hvreg hsz) b))
(RV.loc_rvector hvec)
hh0 hh1;
assert (Rgl?.region_of (hvreg hsz) hvec == Rgl?.region_of (hvreg hsz) flushed);
// 1-1) For the `modifies` postcondition.
assert (modifies (RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv)) hh0 hh1);
// 1-2) Preservation
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1;
// 1-3) For `mt_safe_elts`
assert (V.size_of flushed == Ghost.reveal j - offset_of i); // head updated
mt_safe_elts_preserved
(lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)
(RV.loc_rvector (V.get hh0 hs lv)) hh0 hh1; // tail not yet
// 1-4) For the `rv_inv` postcondition
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs)) 0 (U32.v lv) (U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v lv);
RV.rv_elems_inv_preserved
hs 0ul lv (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs 0ul lv);
RV.rs_loc_elems_elem_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
0 (U32.v (V.size_of hs))
(U32.v lv + 1) (U32.v (V.size_of hs))
(U32.v lv);
RV.rs_loc_elems_parent_disj
(hvreg hsz) (V.as_seq hh0 hs) (V.frameOf hs)
(U32.v lv + 1) (U32.v (V.size_of hs));
RV.rv_elems_inv_preserved
hs (lv + 1ul) (V.size_of hs) (RV.loc_rvector (V.get hh0 hs lv))
hh0 hh1;
assert (RV.rv_elems_inv hh1 hs (lv + 1ul) (V.size_of hs));
assert (rv_itself_inv hh1 hs);
assert (elems_reg hh1 hs);
// 1-5) Correctness
assert (S.equal (RV.as_seq hh1 flushed)
(S.slice (RV.as_seq hh0 (V.get hh0 hs lv)) (U32.v ofs)
(S.length (RV.as_seq hh0 (V.get hh0 hs lv)))));
/// 2) Assign the flushed vector to `hs` at the level `lv`.
RV.assign hs lv flushed;
let hh2 = HST.get () in
// 2-1) For the `modifies` postcondition.
assert (modifies (V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2);
assert (modifies (loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul))) hh0 hh2);
// 2-2) Preservation
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
RV.rv_loc_elems_preserved
hs (lv + 1ul) (V.size_of hs)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-3) For `mt_safe_elts`
assert (V.size_of (V.get hh2 hs lv) ==
Ghost.reveal j - offset_of i);
mt_safe_elts_preserved
(lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul)
(V.loc_vector_within hs lv (lv + 1ul)) hh1 hh2;
// 2-4) Correctness
RV.as_seq_sub_preserved hs 0ul lv (loc_rvector flushed) hh0 hh1;
RV.as_seq_sub_preserved hs (lv + 1ul) merkle_tree_size_lg (loc_rvector flushed) hh0 hh1;
assert (S.equal (RV.as_seq hh2 hs)
(S.append
(RV.as_seq_sub hh0 hs 0ul lv)
(S.cons (RV.as_seq hh1 flushed)
(RV.as_seq_sub hh0 hs (lv + 1ul) merkle_tree_size_lg))));
as_seq_sub_upd hh0 hs lv (RV.as_seq hh1 flushed);
// if `lv = 31` then `pi <= i <= j < 2` thus `oi = opi`,
// contradicting the branch.
assert (lv + 1ul < merkle_tree_size_lg);
assert (U32.v (Ghost.reveal j / 2ul) < pow2 (32 - U32.v (lv + 1ul)));
assert (RV.rv_inv hh2 hs);
assert (mt_safe_elts hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul));
/// 3) Recursion
mt_flush_to_ hsz (lv + 1ul) hs (pi / 2ul) (i / 2ul)
(Ghost.hide (Ghost.reveal j / 2ul));
let hh3 = HST.get () in
// 3-0) Memory safety brought from the postcondition of the recursion
assert (modifies
(loc_union
(loc_union
(RV.rs_loc_elem (hvreg hsz) (V.as_seq hh0 hs) (U32.v lv))
(V.loc_vector_within hs lv (lv + 1ul)))
(loc_union
(RV.rv_loc_elems hh0 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs))))
hh0 hh3);
mt_flush_to_modifies_rec_helper lv hs hh0;
V.loc_vector_within_disjoint hs lv (lv + 1ul) (lv + 1ul) (V.size_of hs);
V.loc_vector_within_included hs lv (lv + 1ul);
RV.rv_loc_elems_included hh2 hs (lv + 1ul) (V.size_of hs);
assert (loc_disjoint
(V.loc_vector_within hs lv (lv + 1ul))
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs)));
V.get_preserved hs lv
(loc_union
(RV.rv_loc_elems hh2 hs (lv + 1ul) (V.size_of hs))
(V.loc_vector_within hs (lv + 1ul) (V.size_of hs)))
hh2 hh3;
assert (V.size_of (V.get hh3 hs lv) ==
Ghost.reveal j - offset_of i);
assert (RV.rv_inv hh3 hs);
mt_safe_elts_constr hh3 lv hs i (Ghost.reveal j);
assert (mt_safe_elts hh3 lv hs i (Ghost.reveal j));
// 3-1) Correctness
mt_safe_elts_spec hh2 (lv + 1ul) hs (pi / 2ul) (Ghost.reveal j / 2ul);
assert (S.equal (RV.as_seq hh3 hs)
(MTH.mt_flush_to_ (U32.v lv + 1) (RV.as_seq hh2 hs)
(U32.v pi / 2) (U32.v i / 2) (U32.v (Ghost.reveal j) / 2)));
mt_safe_elts_spec hh0 lv hs pi (Ghost.reveal j);
MTH.mt_flush_to_rec
(U32.v lv) (RV.as_seq hh0 hs)
(U32.v pi) (U32.v i) (U32.v (Ghost.reveal j));
assert (S.equal (RV.as_seq hh3 hs)
(MTH.mt_flush_to_ (U32.v lv) (RV.as_seq hh0 hs)
(U32.v pi) (U32.v i) (U32.v (Ghost.reveal j))))
end
#pop-options
// `mt_flush_to` flushes old hashes in the Merkle tree. It removes hash elements
// from `MT?.i` to **`offset_of (idx - 1)`**, but maintains the tree structure,
// i.e., the tree still holds some old internal hashes (compressed from old
// hashes) which are required to generate Merkle paths for remaining hashes.
//
// Note that `mt_flush_to` (and `mt_flush`) always remain at least one base hash
// elements. If there are `MT?.j` number of elements in the tree, because of the
// precondition `MT?.i <= idx < MT?.j` we still have `idx`-th element after
// flushing.
private inline_for_extraction
val mt_flush_to_pre_nst: mtv:merkle_tree -> idx:offset_t -> Tot bool
let mt_flush_to_pre_nst mtv idx =
offsets_connect (MT?.offset mtv) idx &&
([@inline_let] let idx = split_offset (MT?.offset mtv) idx in
idx >= MT?.i mtv &&
idx < MT?.j mtv)
val mt_flush_to_pre: mt:const_mt_p -> idx:offset_t -> HST.ST bool
(requires (fun h0 -> mt_safe h0 (CB.cast mt)))
(ensures (fun _ _ _ -> True))
let mt_flush_to_pre mt idx =
let mt = CB.cast mt in
let h0 = HST.get() in
let mtv = !*mt in
mt_flush_to_pre_nst mtv idx
#push-options "--z3rlimit 100 --initial_fuel 1 --max_fuel 1"
val mt_flush_to:
mt:mt_p ->
idx:offset_t ->
HST.ST unit
(requires (fun h0 -> mt_safe h0 mt /\ mt_flush_to_pre_nst (B.get h0 mt 0) idx))
(ensures (fun h0 _ h1 ->
// memory safety
modifies (mt_loc mt) h0 h1 /\
mt_safe h1 mt /\
// correctness
(let mtv0 = B.get h0 mt 0 in
let mtv1 = B.get h1 mt 0 in
let off = MT?.offset mtv0 in
let idx = split_offset off idx in
MT?.hash_size mtv0 = MT?.hash_size mtv1 /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"MerkleTree.New.High.fst.checked",
"MerkleTree.Low.VectorExtras.fst.checked",
"MerkleTree.Low.Hashfunctions.fst.checked",
"MerkleTree.Low.Datastructures.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.Instances.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Monotonic.HyperHeap.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.All.fst.checked",
"EverCrypt.Helpers.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.Low.fst"
} | [
{
"abbrev": false,
"full_module": "MerkleTree.Low.VectorExtras",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low.Hashfunctions",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low.Datastructures",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "MerkleTree.New.High",
"short_module": "MTH"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Regional.Instances",
"short_module": "RVI"
},
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.HyperHeap",
"short_module": "HH"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": "MHS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.Regional.Instances",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | mt: MerkleTree.Low.mt_p -> idx: MerkleTree.Low.offset_t -> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"MerkleTree.Low.mt_p",
"MerkleTree.Low.offset_t",
"MerkleTree.Low.mt_safe_elts_preserved",
"MerkleTree.Low.__proj__MT__item__hash_size",
"FStar.UInt32.__uint_to_t",
"MerkleTree.Low.__proj__MT__item__j",
"LowStar.Monotonic.Buffer.loc_buffer",
"MerkleTree.Low.merkle_tree",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"LowStar.Regional.__proj__Rgl__item__r_sep",
"MerkleTree.Low.Datastructures.hash_size_t",
"MerkleTree.Low.Datastructures.hash",
"MerkleTree.Low.Datastructures.hreg",
"MerkleTree.Low.__proj__MT__item__mroot",
"LowStar.RVector.as_seq_preserved",
"MerkleTree.Low.__proj__MT__item__rhs",
"MerkleTree.Low.Datastructures.hash_vec",
"MerkleTree.Low.Datastructures.hvreg",
"MerkleTree.Low.__proj__MT__item__hs",
"LowStar.RVector.rv_inv_preserved",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.BufferOps.op_Star_Equals",
"MerkleTree.Low.MT",
"MerkleTree.Low.__proj__MT__item__offset",
"MerkleTree.Low.__proj__MT__item__rhs_ok",
"MerkleTree.Low.__proj__MT__item__hash_spec",
"MerkleTree.Low.__proj__MT__item__hash_fun",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.RVector.rv_loc_elems",
"LowStar.Vector.size_of",
"LowStar.Vector.loc_vector_within",
"LowStar.Vector.loc_vector_within_included",
"LowStar.RVector.rv_loc_elems_included",
"MerkleTree.Low.mt_flush_to_",
"MerkleTree.Low.__proj__MT__item__i",
"FStar.Ghost.hide",
"MerkleTree.Low.index_t",
"MerkleTree.Low.Datastructures.hash_vv",
"Prims.b2t",
"Prims.op_Equality",
"LowStar.Vector.uint32_t",
"MerkleTree.Low.merkle_tree_size_lg",
"MerkleTree.Low.split_offset",
"Prims.l_and",
"FStar.UInt32.lte",
"MerkleTree.Low.add64_fits",
"LowStar.BufferOps.op_Bang_Star"
] | [] | false | true | false | false | false | let mt_flush_to mt idx =
| let hh0 = HST.get () in
let mtv = !*mt in
let offset = MT?.offset mtv in
let j = MT?.j mtv in
let hsz = MT?.hash_size mtv in
let idx = split_offset offset idx in
let hs = MT?.hs mtv in
mt_flush_to_ hsz 0ul hs (MT?.i mtv) idx (Ghost.hide (MT?.j mtv));
let hh1 = HST.get () in
RV.rv_loc_elems_included hh0 hs 0ul (V.size_of hs);
V.loc_vector_within_included hs 0ul (V.size_of hs);
RV.rv_inv_preserved (MT?.rhs mtv)
(loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))
)
hh0
hh1;
RV.as_seq_preserved (MT?.rhs mtv)
(loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))
)
hh0
hh1;
Rgl?.r_sep (hreg (MT?.hash_size mtv))
(MT?.mroot mtv)
(loc_union (RV.rv_loc_elems hh0 hs 0ul (V.size_of hs)) (V.loc_vector_within hs 0ul (V.size_of hs))
)
hh0
hh1;
mt *=
MT (MT?.hash_size mtv)
(MT?.offset mtv)
idx
(MT?.j mtv)
hs
(MT?.rhs_ok mtv)
(MT?.rhs mtv)
(MT?.mroot mtv)
(MT?.hash_spec mtv)
(MT?.hash_fun mtv);
let hh2 = HST.get () in
RV.rv_inv_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.rv_inv_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.hs mtv) (B.loc_buffer mt) hh1 hh2;
RV.as_seq_preserved (MT?.rhs mtv) (B.loc_buffer mt) hh1 hh2;
Rgl?.r_sep (hreg (MT?.hash_size mtv)) (MT?.mroot mtv) (B.loc_buffer mt) hh1 hh2;
mt_safe_elts_preserved 0ul hs idx (MT?.j mtv) (B.loc_buffer mt) hh1 hh2 | false |
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicFlagValuesAreSame | val publicFlagValuesAreSame : ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags) | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 17,
"start_col": 0,
"start_line": 16
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__flagsTaint",
"Vale.Arch.HeapTypes_s.Public",
"Prims.eq2",
"Vale.X64.Machine_Semantics_s.flags_t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Prims.logical"
] | [] | false | false | false | true | true | let publicFlagValuesAreSame (ts: leakage_taints) (s1 s2: machine_state) =
| ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags) | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicMemValuesAreSame | val publicMemValuesAreSame : s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 118,
"end_line": 39,
"start_col": 0,
"start_line": 37
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_Forall",
"Prims.int",
"Vale.X64.Leakage_s.publicMemValueIsSame",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Machine_Semantics_s.op_String_Access",
"Vale.Def.Types_s.nat8",
"Vale.Arch.HeapTypes_s.taint",
"Prims.logical"
] | [] | false | false | false | true | true | let publicMemValuesAreSame (s1 s2: machine_state) =
| forall x.
{:pattern
(heap_taint s1.ms_heap).[ x ]\/(heap_taint s2.ms_heap).[ x ]\/(heap_get s1.ms_heap).[ x ]\/(heap_get
s2.ms_heap).[ x ]}
publicMemValueIsSame (heap_get s1.ms_heap)
(heap_get s2.ms_heap)
(heap_taint s1.ms_heap)
(heap_taint s2.ms_heap)
x | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicMemValueIsSame | val publicMemValueIsSame : mem1: Vale.Arch.MachineHeap_s.machine_heap ->
mem2: Vale.Arch.MachineHeap_s.machine_heap ->
memTaint1: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
memTaint2: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
x: Prims.int
-> Prims.logical | let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x] | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 35,
"start_col": 0,
"start_line": 30
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
mem1: Vale.Arch.MachineHeap_s.machine_heap ->
mem2: Vale.Arch.MachineHeap_s.machine_heap ->
memTaint1: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
memTaint2: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
x: Prims.int
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Map.t",
"Prims.int",
"Vale.Arch.HeapTypes_s.taint",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_BarBar",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.X64.Machine_Semantics_s.op_String_Access",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Prims.logical"
] | [] | false | false | false | true | true | let publicMemValueIsSame (mem1 mem2: machine_heap) (memTaint1 memTaint2: Map.t int taint) (x: int) =
| (Public? (memTaint1.[ x ]) || Public? (memTaint2.[ x ])) ==> mem1.[ x ] == mem2.[ x ] | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicStackValuesAreSame | val publicStackValuesAreSame : s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 52,
"start_col": 0,
"start_line": 48
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Vale.X64.Machine_Semantics_s.machine_state -> s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Prims.int",
"Vale.Def.Types_s.nat8",
"Prims.l_Forall",
"Vale.X64.Leakage_s.publicStackValueIsSame",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Machine_Semantics_s.op_String_Access",
"Vale.Arch.HeapTypes_s.taint",
"Prims.logical",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack"
] | [] | false | false | false | true | true | let publicStackValuesAreSame (s1 s2: machine_state) =
| let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x. {:pattern s1.ms_stackTaint.[ x ]\/s2.ms_stackTaint.[ x ]\/stack1.[ x ]\/stack2.[ x ]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicStackValueIsSame | val publicStackValueIsSame : stack1: Vale.Arch.MachineHeap_s.machine_heap ->
stack2: Vale.Arch.MachineHeap_s.machine_heap ->
stackTaint1: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
stackTaint2: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
x: Prims.int
-> Prims.logical | let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x] | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 46,
"start_col": 0,
"start_line": 41
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
stack1: Vale.Arch.MachineHeap_s.machine_heap ->
stack2: Vale.Arch.MachineHeap_s.machine_heap ->
stackTaint1: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
stackTaint2: FStar.Map.t Prims.int Vale.Arch.HeapTypes_s.taint ->
x: Prims.int
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Map.t",
"Prims.int",
"Vale.Arch.HeapTypes_s.taint",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_BarBar",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.X64.Machine_Semantics_s.op_String_Access",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Prims.logical"
] | [] | false | false | false | true | true | let publicStackValueIsSame
(stack1 stack2: machine_heap)
(stackTaint1 stackTaint2: Map.t int taint)
(x: int)
=
| (Public? (stackTaint1.[ x ]) || Public? (stackTaint2.[ x ])) ==> stack1.[ x ] == stack2.[ x ] | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicValuesAreSame | val publicValuesAreSame : ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2 | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 60,
"start_col": 0,
"start_line": 54
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_and",
"Vale.X64.Leakage_s.publicRegisterValuesAreSame",
"Vale.X64.Leakage_s.publicFlagValuesAreSame",
"Vale.X64.Leakage_s.publicCfFlagValuesAreSame",
"Vale.X64.Leakage_s.publicOfFlagValuesAreSame",
"Vale.X64.Leakage_s.publicMemValuesAreSame",
"Vale.X64.Leakage_s.publicStackValuesAreSame",
"Prims.logical"
] | [] | false | false | false | true | true | let publicValuesAreSame (ts: leakage_taints) (s1 s2: machine_state) =
| publicRegisterValuesAreSame ts s1 s2 /\ publicFlagValuesAreSame ts s1 s2 /\
publicCfFlagValuesAreSame ts s1 s2 /\ publicOfFlagValuesAreSame ts s1 s2 /\
publicMemValuesAreSame s1 s2 /\ publicStackValuesAreSame s1 s2 | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.isConstantTime | val isConstantTime : code: Vale.X64.Machine_Semantics_s.code -> ts: Vale.X64.Leakage_s.leakage_taints -> Prims.logical | let isConstantTime (code:code) (ts:leakage_taints) =
forall s1 s2 fuel.
isConstantTimeGivenStates code fuel ts s1 s2 | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 78,
"start_col": 0,
"start_line": 76
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace
let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | code: Vale.X64.Machine_Semantics_s.code -> ts: Vale.X64.Leakage_s.leakage_taints -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Vale.X64.Leakage_s.leakage_taints",
"Prims.l_Forall",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Vale.X64.Leakage_s.isConstantTimeGivenStates",
"Prims.logical"
] | [] | false | false | false | true | true | let isConstantTime (code: code) (ts: leakage_taints) =
| forall s1 s2 fuel. isConstantTimeGivenStates code fuel ts s1 s2 | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.isExplicitLeakageFree | val isExplicitLeakageFree : code: Vale.X64.Machine_Semantics_s.code ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints
-> Prims.logical | let isExplicitLeakageFree (code:code) (ts:leakage_taints) (ts':leakage_taints) =
forall s1 s2 fuel.
isExplicitLeakageFreeGivenStates code fuel ts ts' s1 s2 | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 99,
"start_col": 0,
"start_line": 97
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace
let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace
let isConstantTime (code:code) (ts:leakage_taints) =
forall s1 s2 fuel.
isConstantTimeGivenStates code fuel ts s1 s2
let is_explicit_leakage_free_lhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= s1.ms_ok /\ s2.ms_ok /\ constTimeInvariant ts s1 s2 /\
(let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ (Some?.v r1).ms_ok /\ (Some?.v r2).ms_ok)
let is_explicit_leakage_free_rhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ publicValuesAreSame ts' (Some?.v r1) (Some?.v r2)
let isExplicitLeakageFreeGivenStates (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= is_explicit_leakage_free_lhs code fuel ts ts' s1 s2 ==> is_explicit_leakage_free_rhs code fuel ts ts' s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Machine_Semantics_s.code ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Vale.X64.Leakage_s.leakage_taints",
"Prims.l_Forall",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Vale.X64.Leakage_s.isExplicitLeakageFreeGivenStates",
"Prims.logical"
] | [] | false | false | false | true | true | let isExplicitLeakageFree (code: code) (ts ts': leakage_taints) =
| forall s1 s2 fuel. isExplicitLeakageFreeGivenStates code fuel ts ts' s1 s2 | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicCfFlagValuesAreSame | val publicCfFlagValuesAreSame : ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags) | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 20,
"start_col": 0,
"start_line": 19
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.b2t",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__cfFlagsTaint",
"Prims.op_Equality",
"Vale.X64.Machine_Semantics_s.flag_val_t",
"Vale.X64.Machine_Semantics_s.cf",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Prims.logical"
] | [] | false | false | false | true | true | let publicCfFlagValuesAreSame (ts: leakage_taints) (s1 s2: machine_state) =
| Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags) | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicRegisterValuesAreSame | val publicRegisterValuesAreSame : ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r) | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 28,
"start_col": 0,
"start_line": 25
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_Forall",
"Vale.X64.Machine_s.reg",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.Machine_s.t_reg",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Prims.logical"
] | [] | false | false | false | true | true | let publicRegisterValuesAreSame (ts: leakage_taints) (s1 s2: machine_state) =
| forall r. {:pattern ts.regTaint r\/s1.ms_regs r\/s2.ms_regs r}
ts.regTaint r = Public ==> (s1.ms_regs r = s2.ms_regs r) | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.publicOfFlagValuesAreSame | val publicOfFlagValuesAreSame : ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags) | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 23,
"start_col": 0,
"start_line": 22
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.b2t",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__ofFlagsTaint",
"Prims.op_Equality",
"Vale.X64.Machine_Semantics_s.flag_val_t",
"Vale.X64.Machine_Semantics_s.overflow",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Prims.logical"
] | [] | false | false | false | true | true | let publicOfFlagValuesAreSame (ts: leakage_taints) (s1 s2: machine_state) =
| Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags) | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.isExplicitLeakageFreeGivenStates | val isExplicitLeakageFreeGivenStates : code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let isExplicitLeakageFreeGivenStates (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= is_explicit_leakage_free_lhs code fuel ts ts' s1 s2 ==> is_explicit_leakage_free_rhs code fuel ts ts' s1 s2 | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 111,
"end_line": 95,
"start_col": 0,
"start_line": 93
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace
let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace
let isConstantTime (code:code) (ts:leakage_taints) =
forall s1 s2 fuel.
isConstantTimeGivenStates code fuel ts s1 s2
let is_explicit_leakage_free_lhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= s1.ms_ok /\ s2.ms_ok /\ constTimeInvariant ts s1 s2 /\
(let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ (Some?.v r1).ms_ok /\ (Some?.v r2).ms_ok)
let is_explicit_leakage_free_rhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ publicValuesAreSame ts' (Some?.v r1) (Some?.v r2) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Prims.nat",
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Vale.X64.Leakage_s.is_explicit_leakage_free_lhs",
"Vale.X64.Leakage_s.is_explicit_leakage_free_rhs",
"Prims.logical"
] | [] | false | false | false | true | true | let isExplicitLeakageFreeGivenStates
(code: code)
(fuel: nat)
(ts ts': leakage_taints)
(s1 s2: machine_state)
=
| is_explicit_leakage_free_lhs code fuel ts ts' s1 s2 ==>
is_explicit_leakage_free_rhs code fuel ts ts' s1 s2 | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.isLeakageFree | val isLeakageFree : code: Vale.X64.Machine_Semantics_s.code ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints
-> Prims.logical | let isLeakageFree (code:code) (ts:leakage_taints) (ts':leakage_taints) =
isConstantTime code ts
/\ isExplicitLeakageFree code ts ts' | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 103,
"start_col": 0,
"start_line": 101
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace
let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace
let isConstantTime (code:code) (ts:leakage_taints) =
forall s1 s2 fuel.
isConstantTimeGivenStates code fuel ts s1 s2
let is_explicit_leakage_free_lhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= s1.ms_ok /\ s2.ms_ok /\ constTimeInvariant ts s1 s2 /\
(let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ (Some?.v r1).ms_ok /\ (Some?.v r2).ms_ok)
let is_explicit_leakage_free_rhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ publicValuesAreSame ts' (Some?.v r1) (Some?.v r2)
let isExplicitLeakageFreeGivenStates (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= is_explicit_leakage_free_lhs code fuel ts ts' s1 s2 ==> is_explicit_leakage_free_rhs code fuel ts ts' s1 s2
let isExplicitLeakageFree (code:code) (ts:leakage_taints) (ts':leakage_taints) =
forall s1 s2 fuel.
isExplicitLeakageFreeGivenStates code fuel ts ts' s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Machine_Semantics_s.code ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Vale.X64.Leakage_s.leakage_taints",
"Prims.l_and",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Leakage_s.isExplicitLeakageFree",
"Prims.logical"
] | [] | false | false | false | true | true | let isLeakageFree (code: code) (ts ts': leakage_taints) =
| isConstantTime code ts /\ isExplicitLeakageFree code ts ts' | false |
|
IMSTsub.fst | IMSTsub.st_pre | val st_pre : s: Type0 -> Type | let st_pre (s:Type0) = s -> GTot Type0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 30,
"start_col": 0,
"start_line": 30
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | s: Type0 -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let st_pre (s: Type0) =
| s -> GTot Type0 | false |
|
IMSTsub.fst | IMSTsub.st_post' | val st_post' : s: Type0 -> a: Type -> pre: Type -> Type | let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | s: Type0 -> a: Type -> pre: Type -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let st_post' (s: Type0) (a pre: Type) =
| a -> _: s{pre} -> GTot Type0 | false |
|
IMSTsub.fst | IMSTsub.st_wp | val st_wp : a: Type -> Type | let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s) | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Pervasives.st_post_h",
"FStar.Pervasives.st_pre_h"
] | [] | false | false | false | true | true | let st_wp (a: Type) =
| s: Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s) | false |
|
IMSTsub.fst | IMSTsub.st_return | val st_return : a: Type -> x: a -> s: Type0 -> rel: FStar.Preorder.preorder s -> post: IMSTsub.st_post s a -> s0: s
-> Prims.logical | let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 38,
"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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> s: Type0 -> rel: FStar.Preorder.preorder s -> post: IMSTsub.st_post s a -> s0: s
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Prims.logical"
] | [] | false | false | false | true | true | let st_return (a: Type) (x: a) (s: Type0) (rel: preorder s) (post: st_post s a) (s0: s) =
| forall v. v == x ==> post v s0 | false |
|
IMSTsub.fst | IMSTsub.st_post | val st_post : s: Type0 -> a: Type -> Type | let st_post (s:Type0) (a:Type) = st_post_h' s a True | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 32,
"start_col": 0,
"start_line": 32
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | s: Type0 -> a: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.st_post_h'",
"Prims.l_True"
] | [] | false | false | false | true | true | let st_post (s: Type0) (a: Type) =
| st_post_h' s a True | false |
|
IMSTsub.fst | IMSTsub.st_bind | val st_bind : a: Type ->
b: Type ->
wp1: IMSTsub.st_wp a ->
wp2: (_: a -> IMSTsub.st_wp b) ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s b ->
s0: s
-> Type0 | let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 44,
"start_col": 0,
"start_line": 41
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 ->
wp1: IMSTsub.st_wp a ->
wp2: (_: a -> IMSTsub.st_wp b) ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s b ->
s0: s
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_wp",
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_True"
] | [] | false | false | false | true | true | let st_bind
(a b: Type)
(wp1: st_wp a)
(wp2: (a -> Tot (st_wp b)))
(s: Type0)
(rel: preorder s)
(post: st_post s b)
(s0: s)
=
| wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0 | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.constTimeInvariant | val constTimeInvariant : ts: Vale.X64.Leakage_s.leakage_taints ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
s': Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 64,
"start_col": 0,
"start_line": 62
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ts: Vale.X64.Leakage_s.leakage_taints ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
s': Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_and",
"Vale.X64.Leakage_s.publicValuesAreSame",
"Prims.b2t",
"Prims.op_Equality",
"Prims.list",
"Vale.X64.Machine_s.observation",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"Prims.logical"
] | [] | false | false | false | true | true | let constTimeInvariant (ts: leakage_taints) (s s': machine_state) =
| publicValuesAreSame ts s s' /\ s.ms_trace = s'.ms_trace | false |
|
IMSTsub.fst | IMSTsub.st_ite | val st_ite : a: Type ->
wp: IMSTsub.st_wp a ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s a ->
s0: s
-> Prims.logical | let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 56,
"start_col": 0,
"start_line": 53
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: IMSTsub.st_wp a ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s a ->
s0: s
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_wp",
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.guard_free",
"Prims.logical"
] | [] | false | false | false | true | true | let st_ite (a: Type) (wp: st_wp a) (s: Type0) (rel: preorder s) (post: st_post s a) (s0: s) =
| forall (k: st_post s a).
(forall (x: a) (s1: s). {:pattern (guard_free (k x s1))} post x s1 ==> k x s1) ==> wp s rel k s0 | false |
|
IMSTsub.fst | IMSTsub.st_close | val st_close : a: Type ->
b: Type ->
wp: (_: b -> Prims.GTot (IMSTsub.st_wp a)) ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
p: IMSTsub.st_post s a ->
s0: s
-> Prims.logical | let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 66,
"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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: (_: b -> Prims.GTot (IMSTsub.st_wp a)) ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
p: IMSTsub.st_post s a ->
s0: s
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_wp",
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_Forall",
"Prims.logical"
] | [] | false | false | false | false | true | let st_close
(a b: Type)
(wp: (b -> GTot (st_wp a)))
(s: Type0)
(rel: preorder s)
(p: st_post s a)
(s0: s)
=
| forall x. wp x s rel p s0 | false |
|
IMSTsub.fst | IMSTsub.st_if_then_else | val st_if_then_else : a: Type ->
p: Type0 ->
wp_then: IMSTsub.st_wp a ->
wp_else: IMSTsub.st_wp a ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s a ->
s0: s
-> Prims.logical | let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0) | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 50,
"start_col": 0,
"start_line": 47
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 ->
p: Type0 ->
wp_then: IMSTsub.st_wp a ->
wp_else: IMSTsub.st_wp a ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s a ->
s0: s
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_wp",
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_ITE",
"Prims.logical"
] | [] | false | false | false | true | true | let st_if_then_else
(a p: Type)
(wp_then wp_else: st_wp a)
(s: Type0)
(rel: preorder s)
(post: st_post s a)
(s0: s)
=
| l_ITE p (wp_then s rel post s0) (wp_else s rel post s0) | false |
|
IMSTsub.fst | IMSTsub.st_trivial | val st_trivial : a: Type -> wp: IMSTsub.st_wp a -> Prims.logical | let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 70,
"start_col": 0,
"start_line": 69
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: IMSTsub.st_wp a -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_wp",
"Prims.l_Forall",
"FStar.Preorder.preorder",
"Prims.l_True",
"Prims.logical"
] | [] | false | false | false | true | true | let st_trivial (a: Type) (wp: st_wp a) =
| forall s rel s0. wp s rel (fun _ _ -> True) s0 | false |
|
IMSTsub.fst | IMSTsub.st_stronger | val st_stronger : a: Type -> wp1: IMSTsub.st_wp a -> wp2: IMSTsub.st_wp a -> Prims.logical | let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> wp1: IMSTsub.st_wp a -> wp2: IMSTsub.st_wp a -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_wp",
"Prims.l_Forall",
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_imp",
"Prims.logical"
] | [] | false | false | false | true | true | let st_stronger (a: Type) (wp1 wp2: st_wp a) =
| forall (s: Type0) (rel: preorder s) (p: st_post s a) (s0: s). wp1 s rel p s0 ==> wp2 s rel p s0 | false |
|
IMSTsub.fst | IMSTsub.st_wp' | val st_wp' : a: Type -> s: Type0 -> Type | let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s) | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 98,
"start_col": 0,
"start_line": 97
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> s: Type0 -> Type | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.st_post",
"IMSTsub.st_pre"
] | [] | false | false | false | true | true | let st_wp' (a: Type) (s: Type0) =
| st_post s a -> Tot (st_pre s) | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.is_explicit_leakage_free_lhs | val is_explicit_leakage_free_lhs : code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let is_explicit_leakage_free_lhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= s1.ms_ok /\ s2.ms_ok /\ constTimeInvariant ts s1 s2 /\
(let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ (Some?.v r1).ms_ok /\ (Some?.v r2).ms_ok) | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 85,
"start_col": 0,
"start_line": 80
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace
let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace
let isConstantTime (code:code) (ts:leakage_taints) =
forall s1 s2 fuel.
isConstantTimeGivenStates code fuel ts s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Prims.nat",
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Leakage_s.constTimeInvariant",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Prims.logical"
] | [] | false | false | false | true | true | let is_explicit_leakage_free_lhs
(code: code)
(fuel: nat)
(ts ts': leakage_taints)
(s1 s2: machine_state)
=
| s1.ms_ok /\ s2.ms_ok /\ constTimeInvariant ts s1 s2 /\
(let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ (Some?.v r1).ms_ok /\ (Some?.v r2).ms_ok) | false |
|
IMSTsub.fst | IMSTsub.lift_div_imst | val lift_div_imst : a: Type ->
wp: Prims.pure_wp a ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s a ->
s0: s
-> Prims.pure_pre | let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0) | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 91,
"start_col": 0,
"start_line": 89
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 ->
s: Type0 ->
rel: FStar.Preorder.preorder s ->
post: IMSTsub.st_post s a ->
s0: s
-> Prims.pure_pre | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"FStar.Preorder.preorder",
"IMSTsub.st_post",
"Prims.l_True",
"Prims.pure_pre"
] | [] | false | false | false | true | false | let lift_div_imst (a: Type) (wp: pure_wp a) (s: Type0) (rel: preorder s) (post: st_post s a) (s0: s) =
| wp (fun x -> post x s0) | false |
|
IMSTsub.fst | IMSTsub.nat_rel' | val nat_rel':relation nat | val nat_rel':relation nat | let nat_rel' : relation nat
= fun i j -> i <= j | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 125,
"start_col": 0,
"start_line": 124
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1))
let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p
assume val witness (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ q s0 /\ (witnessed #s #rel q ==> p () s0)))
assume val recall (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ witnessed #s #rel q /\ (q s0 ==> p () s0)))
(* Some sample code *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | FStar.Preorder.relation Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual"
] | [] | false | false | false | true | false | let nat_rel':relation nat =
| fun i j -> i <= j | false |
HaclExample2.fst | HaclExample2.five | val five : Type0 | let five = normalize (nat_t_of_nat 5) | {
"file_name": "share/steel/examples/steelc/HaclExample2.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 19,
"start_col": 32,
"start_line": 19
} | module HaclExample2
open Steel.ST.GenElim
open Steel.ST.C.Types
open Steel.C.Typenat
open Steel.C.Typestring
module SZ = FStar.SizeT
module U64 = FStar.UInt64
(** In this file we demonstrate how Steel could be used to manipulate the following data type used in Hacl*:
https://github.com/project-everest/hacl-star/blob/master/code/poly1305/Hacl.Impl.Poly1305.fsti#L18
This Low* definition amounts to the struct definition
struct poly1305_ctx { uint64_t limbs[5]; uint64_t precomp[20]; };
and, with our new model of structs and arrays and pointer-to-field, can be expresesd directly in Steel.
See PointStruct.fst for more detailed explanations of the various definitions needed below.
*) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.C.Types.fst.checked",
"Steel.C.Typestring.fsti.checked",
"Steel.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "HaclExample2.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize",
"Steel.C.Typenat.nat_t_of_nat"
] | [] | false | false | false | true | true | let five =
| normalize (nat_t_of_nat 5) | false |
|
IMSTsub.fst | IMSTsub.witnessed | val witnessed (#s: Type) (#rel: preorder s) (p: predicate s) : Type0 | val witnessed (#s: Type) (#rel: preorder s) (p: predicate s) : Type0 | let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 112,
"start_col": 0,
"start_line": 112
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | p: FStar.Preorder.predicate s -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Preorder.predicate",
"FStar.Monotonic.Witnessed.witnessed"
] | [] | false | false | false | true | true | let witnessed (#s: Type) (#rel: preorder s) (p: predicate s) : Type0 =
| W.witnessed rel p | false |
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.is_explicit_leakage_free_rhs | val is_explicit_leakage_free_rhs : code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let is_explicit_leakage_free_rhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ publicValuesAreSame ts' (Some?.v r1) (Some?.v r2) | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 91,
"start_col": 0,
"start_line": 87
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace
let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace
let isConstantTime (code:code) (ts:leakage_taints) =
forall s1 s2 fuel.
isConstantTimeGivenStates code fuel ts s1 s2
let is_explicit_leakage_free_lhs (code:code) (fuel:nat)
(ts:leakage_taints) (ts':leakage_taints) (s1:machine_state) (s2:machine_state)
= s1.ms_ok /\ s2.ms_ok /\ constTimeInvariant ts s1 s2 /\
(let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ (Some?.v r1).ms_ok /\ (Some?.v r2).ms_ok) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
ts': Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Prims.nat",
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Leakage_s.publicValuesAreSame",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Prims.logical"
] | [] | false | false | false | true | true | let is_explicit_leakage_free_rhs
(code: code)
(fuel: nat)
(ts ts': leakage_taints)
(s1 s2: machine_state)
=
| let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
Some? r1 /\ Some? r2 /\ publicValuesAreSame ts' (Some?.v r1) (Some?.v r2) | false |
|
HaclExample2.fst | HaclExample2.twenty | val twenty : Type0 | let twenty = normalize (nat_t_of_nat 20) | {
"file_name": "share/steel/examples/steelc/HaclExample2.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 72,
"end_line": 20,
"start_col": 32,
"start_line": 20
} | module HaclExample2
open Steel.ST.GenElim
open Steel.ST.C.Types
open Steel.C.Typenat
open Steel.C.Typestring
module SZ = FStar.SizeT
module U64 = FStar.UInt64
(** In this file we demonstrate how Steel could be used to manipulate the following data type used in Hacl*:
https://github.com/project-everest/hacl-star/blob/master/code/poly1305/Hacl.Impl.Poly1305.fsti#L18
This Low* definition amounts to the struct definition
struct poly1305_ctx { uint64_t limbs[5]; uint64_t precomp[20]; };
and, with our new model of structs and arrays and pointer-to-field, can be expresesd directly in Steel.
See PointStruct.fst for more detailed explanations of the various definitions needed below.
*) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.C.Types.fst.checked",
"Steel.C.Typestring.fsti.checked",
"Steel.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "HaclExample2.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize",
"Steel.C.Typenat.nat_t_of_nat"
] | [] | false | false | false | true | true | let twenty =
| normalize (nat_t_of_nat 20) | false |
|
Vale.X64.Leakage_s.fst | Vale.X64.Leakage_s.isConstantTimeGivenStates | val isConstantTimeGivenStates : code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let isConstantTimeGivenStates (code:code) (fuel:nat) (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
( (Some? r1) /\ (Some? r2)
/\ s1.ms_ok /\ (Some?.v r1).ms_ok
/\ s2.ms_ok /\ (Some?.v r2).ms_ok
/\ constTimeInvariant ts s1 s2
) ==> (Some?.v r1).ms_trace = (Some?.v r2).ms_trace | {
"file_name": "vale/specs/hardware/Vale.X64.Leakage_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 74,
"start_col": 0,
"start_line": 67
} | module Vale.X64.Leakage_s
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Machine_Semantics_s
module F = FStar.FunctionalExtensionality
type reg_taint = F.restricted_t reg (fun _ -> taint)
noeq type leakage_taints =
| LeakageTaints: regTaint: reg_taint -> flagsTaint: taint -> cfFlagsTaint: taint -> ofFlagsTaint: taint ->
leakage_taints
let publicFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
ts.flagsTaint = Public ==> (s1.ms_flags == s2.ms_flags)
let publicCfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.cfFlagsTaint ==> (cf s1.ms_flags = cf s2.ms_flags)
let publicOfFlagValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
Public? ts.ofFlagsTaint ==> (overflow s1.ms_flags = overflow s2.ms_flags)
let publicRegisterValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
forall r.{:pattern ts.regTaint r \/ s1.ms_regs r \/ s2.ms_regs r}
ts.regTaint r = Public ==>
(s1.ms_regs r = s2.ms_regs r)
let publicMemValueIsSame
(mem1 mem2:machine_heap)
(memTaint1 memTaint2:Map.t int taint)
(x:int) =
(Public? (memTaint1.[x]) || Public? (memTaint2.[x])) ==>
mem1.[x] == mem2.[x]
let publicMemValuesAreSame (s1:machine_state) (s2:machine_state) =
forall x.{:pattern (heap_taint s1.ms_heap).[x] \/ (heap_taint s2.ms_heap).[x] \/ (heap_get s1.ms_heap).[x] \/ (heap_get s2.ms_heap).[x]}
publicMemValueIsSame (heap_get s1.ms_heap) (heap_get s2.ms_heap) (heap_taint s1.ms_heap) (heap_taint s2.ms_heap) x
let publicStackValueIsSame
(stack1 stack2:machine_heap)
(stackTaint1 stackTaint2:Map.t int taint)
(x:int)
= (Public? (stackTaint1.[x]) || Public? (stackTaint2.[x])) ==>
stack1.[x] == stack2.[x]
let publicStackValuesAreSame (s1:machine_state) (s2:machine_state) =
let Machine_stack _ stack1 = s1.ms_stack in
let Machine_stack _ stack2 = s2.ms_stack in
forall x.{:pattern s1.ms_stackTaint.[x] \/ s2.ms_stackTaint.[x] \/ stack1.[x] \/ stack2.[x]}
publicStackValueIsSame stack1 stack2 s1.ms_stackTaint s2.ms_stackTaint x
let publicValuesAreSame (ts:leakage_taints) (s1:machine_state) (s2:machine_state) =
publicRegisterValuesAreSame ts s1 s2
/\ publicFlagValuesAreSame ts s1 s2
/\ publicCfFlagValuesAreSame ts s1 s2
/\ publicOfFlagValuesAreSame ts s1 s2
/\ publicMemValuesAreSame s1 s2
/\ publicStackValuesAreSame s1 s2
let constTimeInvariant (ts:leakage_taints) (s:machine_state) (s':machine_state) =
publicValuesAreSame ts s s'
/\ s.ms_trace = s'.ms_trace | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Leakage_s.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
ts: Vale.X64.Leakage_s.leakage_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.code",
"Prims.nat",
"Vale.X64.Leakage_s.leakage_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Leakage_s.constTimeInvariant",
"Prims.op_Equality",
"Prims.list",
"Vale.X64.Machine_s.observation",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Prims.logical"
] | [] | false | false | false | true | true | let isConstantTimeGivenStates (code: code) (fuel: nat) (ts: leakage_taints) (s1 s2: machine_state) =
| let r1 = machine_eval_code code fuel s1 in
let r2 = machine_eval_code code fuel s2 in
((Some? r1) /\ (Some? r2) /\ s1.ms_ok /\ (Some?.v r1).ms_ok /\ s2.ms_ok /\ (Some?.v r2).ms_ok /\
constTimeInvariant ts s1 s2) ==>
(Some?.v r1).ms_trace = (Some?.v r2).ms_trace | false |
|
IMSTsub.fst | IMSTsub.idx | val idx (#a: Type) (s: Type0) (rel: preorder s) (wp: st_wp' a s) : st_wp a | val idx (#a: Type) (s: Type0) (rel: preorder s) (wp: st_wp' a s) : st_wp a | let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 87,
"end_line": 103,
"start_col": 0,
"start_line": 102
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | s: Type0 -> rel: FStar.Preorder.preorder s -> wp: IMSTsub.st_wp' a s -> IMSTsub.st_wp a | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"IMSTsub.st_wp'",
"FStar.Pervasives.st_post_h",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"Prims.l_imp",
"IMSTsub.st_wp"
] | [] | false | false | false | true | false | let idx (#a: Type) (s: Type0) (rel: preorder s) (wp: st_wp' a s) : st_wp a =
| fun s' rel' post s0 -> s == s' /\ (forall x y. rel x y ==> rel' x y) /\ wp post s0 | false |
IMSTsub.fst | IMSTsub.nat_rel | val nat_rel:preorder nat | val nat_rel:preorder nat | let nat_rel : preorder nat = nat_rel' | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 127,
"start_col": 0,
"start_line": 127
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1))
let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p
assume val witness (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ q s0 /\ (witnessed #s #rel q ==> p () s0)))
assume val recall (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ witnessed #s #rel q /\ (q s0 ==> p () s0)))
(* Some sample code *)
let nat_rel' : relation nat
= fun i j -> i <= j | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | FStar.Preorder.preorder Prims.nat | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.nat_rel'"
] | [] | false | false | false | true | false | let nat_rel:preorder nat =
| nat_rel' | false |
IMSTsub.fst | IMSTsub.eq_rel' | val eq_rel':relation nat | val eq_rel':relation nat | let eq_rel' : relation nat
= fun i j -> i = j | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 130,
"start_col": 0,
"start_line": 129
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1))
let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p
assume val witness (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ q s0 /\ (witnessed #s #rel q ==> p () s0)))
assume val recall (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ witnessed #s #rel q /\ (q s0 ==> p () s0)))
(* Some sample code *)
let nat_rel' : relation nat
= fun i j -> i <= j
let nat_rel : preorder nat = nat_rel' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | FStar.Preorder.relation Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_Equality"
] | [] | false | false | false | true | false | let eq_rel':relation nat =
| fun i j -> i = j | false |
IMSTsub.fst | IMSTsub.eq_rel | val eq_rel:preorder nat | val eq_rel:preorder nat | let eq_rel : preorder nat = eq_rel' | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 132,
"start_col": 0,
"start_line": 132
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1))
let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p
assume val witness (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ q s0 /\ (witnessed #s #rel q ==> p () s0)))
assume val recall (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ witnessed #s #rel q /\ (q s0 ==> p () s0)))
(* Some sample code *)
let nat_rel' : relation nat
= fun i j -> i <= j
let nat_rel : preorder nat = nat_rel'
let eq_rel' : relation nat
= fun i j -> i = j | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | FStar.Preorder.preorder Prims.nat | Prims.Tot | [
"total"
] | [] | [
"IMSTsub.eq_rel'"
] | [] | false | false | false | true | false | let eq_rel:preorder nat =
| eq_rel' | false |
HaclExample2.fst | HaclExample2.comp_name | val comp_name : Type0 | let comp_name = normalize (mk_string_t "HaclExample2.comp") | {
"file_name": "share/steel/examples/steelc/HaclExample2.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 91,
"end_line": 21,
"start_col": 32,
"start_line": 21
} | module HaclExample2
open Steel.ST.GenElim
open Steel.ST.C.Types
open Steel.C.Typenat
open Steel.C.Typestring
module SZ = FStar.SizeT
module U64 = FStar.UInt64
(** In this file we demonstrate how Steel could be used to manipulate the following data type used in Hacl*:
https://github.com/project-everest/hacl-star/blob/master/code/poly1305/Hacl.Impl.Poly1305.fsti#L18
This Low* definition amounts to the struct definition
struct poly1305_ctx { uint64_t limbs[5]; uint64_t precomp[20]; };
and, with our new model of structs and arrays and pointer-to-field, can be expresesd directly in Steel.
See PointStruct.fst for more detailed explanations of the various definitions needed below.
*)
noextract inline_for_extraction let five = normalize (nat_t_of_nat 5) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.C.Types.fst.checked",
"Steel.C.Typestring.fsti.checked",
"Steel.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "HaclExample2.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize",
"Steel.C.Typestring.mk_string_t"
] | [] | false | false | false | true | true | let comp_name =
| normalize (mk_string_t "HaclExample2.comp") | false |
|
HaclExample2.fst | HaclExample2.comp | val comp : Steel.ST.C.Types.Base.typedef (Steel.ST.C.Types.Struct.struct_t0 HaclExample2.comp_name
"HaclExample2.comp"
HaclExample2.comp_fields) | let comp = struct0 comp_name "HaclExample2.comp" comp_fields | {
"file_name": "share/steel/examples/steelc/HaclExample2.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | module HaclExample2
open Steel.ST.GenElim
open Steel.ST.C.Types
open Steel.C.Typenat
open Steel.C.Typestring
module SZ = FStar.SizeT
module U64 = FStar.UInt64
(** In this file we demonstrate how Steel could be used to manipulate the following data type used in Hacl*:
https://github.com/project-everest/hacl-star/blob/master/code/poly1305/Hacl.Impl.Poly1305.fsti#L18
This Low* definition amounts to the struct definition
struct poly1305_ctx { uint64_t limbs[5]; uint64_t precomp[20]; };
and, with our new model of structs and arrays and pointer-to-field, can be expresesd directly in Steel.
See PointStruct.fst for more detailed explanations of the various definitions needed below.
*)
noextract inline_for_extraction let five = normalize (nat_t_of_nat 5)
noextract inline_for_extraction let twenty = normalize (nat_t_of_nat 20)
noextract inline_for_extraction let comp_name = normalize (mk_string_t "HaclExample2.comp")
noextract
inline_for_extraction
[@@norm_field_attr]
let comp_fields =
field_description_cons "limbs" (base_array0 five (scalar U64.t) 5sz) (
field_description_cons "precomp" (base_array0 twenty (scalar U64.t) 20sz) (
field_description_nil
)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.C.Types.fst.checked",
"Steel.C.Typestring.fsti.checked",
"Steel.C.Typenat.fsti.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "HaclExample2.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.C.Typenat",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Steel.ST.C.Types.Base.typedef (Steel.ST.C.Types.Struct.struct_t0 HaclExample2.comp_name
"HaclExample2.comp"
HaclExample2.comp_fields) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.C.Types.Struct.struct0",
"HaclExample2.comp_name",
"Steel.ST.C.Types.Fields.field_t_cons",
"Steel.C.Typestring.string_cons",
"Steel.C.Typestring.cl",
"Steel.C.Typestring.ci",
"Steel.C.Typestring.cm",
"Steel.C.Typestring.cb",
"Steel.C.Typestring.cs",
"Steel.C.Typestring.string_nil",
"Steel.ST.C.Types.Array.base_array_t",
"Steel.ST.C.Types.Scalar.scalar_t",
"FStar.UInt64.t",
"HaclExample2.five",
"FStar.SizeT.__uint_to_t",
"Steel.C.Typestring.cp",
"Steel.C.Typestring.cr",
"Steel.C.Typestring.ce",
"Steel.C.Typestring.cc",
"Steel.C.Typestring.co",
"HaclExample2.twenty",
"Steel.ST.C.Types.Fields.field_t_nil",
"HaclExample2.comp_fields"
] | [] | false | false | false | false | false | let comp =
| struct0 comp_name "HaclExample2.comp" comp_fields | false |
|
IMSTsub.fst | IMSTsub.h | val h: Prims.unit -> IMST nat (idx nat nat_rel (fun p s0 -> forall s1. s1 > s0 ==> p s1 s1)) | val h: Prims.unit -> IMST nat (idx nat nat_rel (fun p s0 -> forall s1. s1 > s0 ==> p s1 s1)) | let h ()
: IMST nat (idx nat nat_rel (fun p s0 -> forall s1 . s1 > s0 ==> p s1 s1))
= let s0 = get #nat #eq_rel () in
put #nat #eq_rel s0;
put #nat #nat_rel (s0 + 1);
let s1 = get #nat #eq_rel () in
s1 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 168,
"start_col": 0,
"start_line": 162
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1))
let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p
assume val witness (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ q s0 /\ (witnessed #s #rel q ==> p () s0)))
assume val recall (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ witnessed #s #rel q /\ (q s0 ==> p () s0)))
(* Some sample code *)
let nat_rel' : relation nat
= fun i j -> i <= j
let nat_rel : preorder nat = nat_rel'
let eq_rel' : relation nat
= fun i j -> i = j
let eq_rel : preorder nat = eq_rel'
open FStar.Mul
let f ()
: IMST unit (idx nat nat_rel (fun p s0 -> p () s0))
= () // without setting unfold for lift_div_imst this fails
let g ()
: IMST nat (idx nat nat_rel (fun p s0 -> forall s1 . s1 > s0 ==> p s0 s1))
= let s0 = get #nat #nat_rel () in
put #nat #nat_rel (s0 + 1);
let s1 = get #nat #nat_rel () in
assert (s1 > 0);
witness #nat #nat_rel (fun n -> n > 0);
put #nat #nat_rel (s1 * 42);
recall #nat #nat_rel (fun n -> n > 0);
let s2 = get #nat #nat_rel () in
assert (s2 > 0);
witness #nat #eq_rel (fun n -> n = s2);
put #nat #nat_rel (s1 * 43);
recall #nat #eq_rel (fun n -> n = s2);
let s3 = get #nat #nat_rel () in
assert (s1 > 0);
assert (s2 = s1 * 42);
assert (s3 = s1 * 43);
assert (s3 = s2);
assert (False); // WHOOPS!!!
s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> IMSTsub.IMST Prims.nat | IMSTsub.IMST | [] | [] | [
"Prims.unit",
"Prims.nat",
"IMSTsub.get",
"IMSTsub.eq_rel",
"IMSTsub.put",
"IMSTsub.nat_rel",
"Prims.op_Addition",
"IMSTsub.idx",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"IMSTsub.st_post",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_GreaterThan"
] | [] | false | true | false | false | false | let h () : IMST nat (idx nat nat_rel (fun p s0 -> forall s1. s1 > s0 ==> p s1 s1)) =
| let s0 = get #nat #eq_rel () in
put #nat #eq_rel s0;
put #nat #nat_rel (s0 + 1);
let s1 = get #nat #eq_rel () in
s1 | false |
IMSTsub.fst | IMSTsub.g | val g: Prims.unit -> IMST nat (idx nat nat_rel (fun p s0 -> forall s1. s1 > s0 ==> p s0 s1)) | val g: Prims.unit -> IMST nat (idx nat nat_rel (fun p s0 -> forall s1. s1 > s0 ==> p s0 s1)) | let g ()
: IMST nat (idx nat nat_rel (fun p s0 -> forall s1 . s1 > s0 ==> p s0 s1))
= let s0 = get #nat #nat_rel () in
put #nat #nat_rel (s0 + 1);
let s1 = get #nat #nat_rel () in
assert (s1 > 0);
witness #nat #nat_rel (fun n -> n > 0);
put #nat #nat_rel (s1 * 42);
recall #nat #nat_rel (fun n -> n > 0);
let s2 = get #nat #nat_rel () in
assert (s2 > 0);
witness #nat #eq_rel (fun n -> n = s2);
put #nat #nat_rel (s1 * 43);
recall #nat #eq_rel (fun n -> n = s2);
let s3 = get #nat #nat_rel () in
assert (s1 > 0);
assert (s2 = s1 * 42);
assert (s3 = s1 * 43);
assert (s3 = s2);
assert (False); // WHOOPS!!!
s0 | {
"file_name": "examples/indexed_effects/IMSTsub.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 160,
"start_col": 0,
"start_line": 140
} | (*
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 IMSTsub
(* A proof-of-concept example of indexed effects (the state-and-preorder indexed, ordered MST effect) encoded using standard F* WP calculi *)
(* WARNING: as demonstrated in the function (g) below, the proposition of subtyping preorders + using witness/recall leads to an inconsistency! *)
open FStar.Preorder
module W = FStar.Monotonic.Witnessed
(* The state-and-preorder indexed MST effect; defined explicitly rather than via DM4F due to the pi-types used in it *)
//s is at a fixed universe level (here #u0) because otherwise sub_effect complains about being too universe polymorphic
let st_pre (s:Type0) = s -> GTot Type0
let st_post' (s:Type0) (a:Type) (pre:Type) = a -> (_:s{pre}) -> GTot Type0
let st_post (s:Type0) (a:Type) = st_post_h' s a True
let st_wp (a:Type) = s:Type0 -> (preorder s) -> st_post_h s a -> Tot (st_pre_h s)
unfold
let st_return (a:Type) (x:a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall v. v == x ==> post v s0
unfold
let st_bind (a:Type) (b:Type)
(wp1:st_wp a) (wp2: (a -> Tot (st_wp b)))
(s:Type0) (rel:preorder s) (post:st_post s b) (s0:s)
= wp1 s rel (fun x s1 -> wp2 x s rel post s1) s0
unfold
let st_if_then_else (a:Type) (p:Type)
(wp_then:st_wp a) (wp_else:st_wp a)
(s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= l_ITE p (wp_then s rel post s0) (wp_else s rel post s0)
unfold
let st_ite (a:Type) (wp:st_wp a) (s:Type0) (rel:preorder s) (post:st_post s a) (s0:s)
= forall (k:st_post s a).
(forall (x:a) (s1:s).{:pattern (guard_free (k x s1))} post x s1 ==> k x s1)
==> wp s rel k s0
unfold
let st_stronger (a:Type) (wp1:st_wp a) (wp2:st_wp a)
= forall (s:Type0) (rel:preorder s) (p:st_post s a) (s0:s) .
wp1 s rel p s0 ==> wp2 s rel p s0
unfold
let st_close (a:Type) (b:Type) (wp:(b -> GTot (st_wp a)))
(s:Type0) (rel:preorder s) (p:st_post s a) (s0:s)
= forall x. wp x s rel p s0
unfold
let st_trivial (a:Type) (wp:st_wp a)
= forall s rel s0. wp s rel (fun _ _ -> True) s0
new_effect {
IMST : result:Type -> wp:st_wp result -> Effect
with
//repr = s:Type0 -> s -> M (a * s) //pi-types currently not supported by DM4F
return_wp = st_return
; bind_wp = st_bind
; if_then_else = st_if_then_else
; ite_wp = st_ite
; stronger = st_stronger
; close_wp = st_close
; trivial = st_trivial
}
(* Standard lifting *)
unfold
let lift_div_imst (a:Type) (wp:pure_wp a) (s:Type0)
(rel:preorder s) (post:st_post s a) (s0:s)
= wp (fun x -> post x s0)
sub_effect DIV ~> IMST = lift_div_imst
(* Non-indexed MST WPs and syntactic sugar for writing effect indices *)
let st_wp' (a:Type) (s:Type0)
= st_post s a -> Tot (st_pre s)
//using idx instead of (><) to avoid complicating things with dependent pairs (mixfix operators, anyone?)
unfold
let idx (#a:Type) (s:Type0) (rel:preorder s) (wp:st_wp' a s) : st_wp a
= fun s' rel' post s0 -> s == s' /\ (forall x y . rel x y ==> rel' x y) /\ wp post s0
(* Standard, but now state-and-preorder indexed get, put, witness, and recall actions *)
assume val get (#s:Type0) (#rel:preorder s) (_:unit) : IMST s (idx s rel (fun p s0 -> p s0 s0))
assume val put (#s:Type0) (#rel:preorder s) (s1:s) : IMST unit (idx s rel (fun p s0 -> rel s0 s1 /\ p () s1))
let witnessed (#s:Type) (#rel:preorder s) (p:predicate s) :Type0 = W.witnessed rel p
assume val witness (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ q s0 /\ (witnessed #s #rel q ==> p () s0)))
assume val recall (#s:Type) (#rel:preorder s) (q:predicate s)
: IMST unit (idx s rel (fun p s0 -> stable q rel /\ witnessed #s #rel q /\ (q s0 ==> p () s0)))
(* Some sample code *)
let nat_rel' : relation nat
= fun i j -> i <= j
let nat_rel : preorder nat = nat_rel'
let eq_rel' : relation nat
= fun i j -> i = j
let eq_rel : preorder nat = eq_rel'
open FStar.Mul
let f ()
: IMST unit (idx nat nat_rel (fun p s0 -> p () s0))
= () // without setting unfold for lift_div_imst this fails | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Monotonic.Witnessed.fsti.checked"
],
"interface_file": false,
"source_file": "IMSTsub.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> IMSTsub.IMST Prims.nat | IMSTsub.IMST | [] | [] | [
"Prims.unit",
"Prims._assert",
"Prims.l_False",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_GreaterThan",
"IMSTsub.get",
"IMSTsub.nat_rel",
"IMSTsub.recall",
"IMSTsub.eq_rel",
"IMSTsub.put",
"IMSTsub.witness",
"Prims.op_Addition",
"IMSTsub.idx",
"IMSTsub.st_post",
"Prims.l_Forall",
"Prims.op_GreaterThanOrEqual",
"Prims.l_imp"
] | [] | false | true | false | false | false | let g () : IMST nat (idx nat nat_rel (fun p s0 -> forall s1. s1 > s0 ==> p s0 s1)) =
| let s0 = get #nat #nat_rel () in
put #nat #nat_rel (s0 + 1);
let s1 = get #nat #nat_rel () in
assert (s1 > 0);
witness #nat #nat_rel (fun n -> n > 0);
put #nat #nat_rel (s1 * 42);
recall #nat #nat_rel (fun n -> n > 0);
let s2 = get #nat #nat_rel () in
assert (s2 > 0);
witness #nat #eq_rel (fun n -> n = s2);
put #nat #nat_rel (s1 * 43);
recall #nat #eq_rel (fun n -> n = s2);
let s3 = get #nat #nat_rel () in
assert (s1 > 0);
assert (s2 = s1 * 42);
assert (s3 = s1 * 43);
assert (s3 = s2);
assert (False);
s0 | false |
Steel.ST.PCMReference.fsti | Steel.ST.PCMReference.pts_to | val pts_to : r: Steel.Memory.ref a pcm -> v: a -> Steel.Effect.Common.vprop | let pts_to (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v:a) = to_vprop (pts_to r v) | {
"file_name": "lib/steel/Steel.ST.PCMReference.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 77,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2020 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 Steel.ST.PCMReference
open FStar.PCM
open FStar.Ghost
open Steel.ST.Util
/// This module exposes the core PCM-based memory model defined in Steel.Memory
/// as stateful Steel computations.
#set-options "--ide_id_info_off"
/// Lifting the pts_to separation logic, PCM-indexed predicate to a vprop.
/// Its selector is non-informative (it is unit)
[@@ __steel_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.PCMReference.fsti"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.Memory.ref a pcm -> v: a -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.PCM.pcm",
"Steel.Memory.ref",
"Steel.Effect.Common.to_vprop",
"Steel.Memory.pts_to",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let pts_to (#a: Type) (#pcm: pcm a) (r: ref a pcm) (v: a) =
| to_vprop (pts_to r v) | false |
|
Steel.ST.PCMReference.fsti | Steel.ST.PCMReference.fact_valid_compat | val fact_valid_compat : fact: Steel.Memory.stable_property pcm -> v: FStar.Ghost.erased a -> Type0 | let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:erased a)
= squash (forall z. compatible pcm v z ==> fact z) | {
"file_name": "lib/steel/Steel.ST.PCMReference.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 52,
"end_line": 128,
"start_col": 0,
"start_line": 125
} | (*
Copyright 2020 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 Steel.ST.PCMReference
open FStar.PCM
open FStar.Ghost
open Steel.ST.Util
/// This module exposes the core PCM-based memory model defined in Steel.Memory
/// as stateful Steel computations.
#set-options "--ide_id_info_off"
/// Lifting the pts_to separation logic, PCM-indexed predicate to a vprop.
/// Its selector is non-informative (it is unit)
[@@ __steel_reduce__]
unfold
let pts_to (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v:a) = to_vprop (pts_to r v)
let pts_to_not_null
(#opened: _)
(#t: Type)
(#p: pcm t)
(r: ref t p)
(v: t)
: STGhost unit opened
(pts_to r v)
(fun _ -> pts_to r v)
True
(fun _ -> r =!= null)
= extract_fact
(pts_to r v)
(r =!= null)
(fun m -> pts_to_not_null r v m)
/// Reading the contents of reference [r] in memory.
/// The returned value [v] is ensured to be compatible with respect
/// to the PCM [pcm] with our current knowledge [v0]
val read (#a:Type)
(#pcm:pcm a)
(r:ref a pcm)
(v0:erased a)
: ST a
(pts_to r v0)
(fun _ -> pts_to r v0)
(requires True)
(ensures fun v -> compatible pcm v0 v /\ True)
/// Writing value [v1] in reference [r], as long as it is frame-preserving with our
/// current knowledge [v0], and that [v1] is a refined value for the PCM [pcm]
val write (#a:Type)
(#pcm:pcm a)
(r:ref a pcm)
(v0:erased a)
(v1:a)
: ST unit
(pts_to r v0)
(fun _ -> pts_to r v1)
(requires frame_preserving pcm v0 v1 /\ pcm.refine v1)
(ensures fun _ -> True)
/// Allocates a new reference, initially storing value [x].
val alloc (#a:Type)
(#pcm:pcm a)
(x:a)
: ST (ref a pcm)
emp
(fun r -> pts_to r x)
(requires pcm.refine x)
(ensures fun _ -> True)
/// Frees reference [r], as long as we have exclusive ownership of [r]
/// according to the governing PCM.
/// Freeing here sets the value to the unit value of the PCM, one can manually
/// call `drop` from Steel.Effect.Atomic to forget it entirely from the context
val free (#a:Type)
(#p:pcm a)
(r:ref a p)
(x:erased a)
: ST unit (pts_to r x) (fun _ -> pts_to r p.p.one)
(requires exclusive p x /\ p.refine p.p.one)
(ensures fun _ -> True)
/// Splits permission on reference [r], in a way that is compatible with the governing PCM.
val split (#inames: _)
(#a:Type)
(#p:pcm a)
(r:ref a p)
(v:erased a)
(v0:erased a)
(v1:erased a)
: STGhost unit inames (pts_to r v)
(fun _ -> pts_to r v0 `star` pts_to r v1)
(requires
composable p v0 v1 /\
v == hide (op p v0 v1))
(ensures fun _ -> True)
/// Gather permissions on reference [r]
val gather (#inames: _)
(#a:Type)
(#p:FStar.PCM.pcm a)
(r:ref a p)
(v0:erased a)
(v1:erased a)
: STGhostT (_:unit{composable p v0 v1}) inames
(pts_to r v0 `star` pts_to r v1)
(fun _ -> pts_to r (op p v0 v1)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.PCMReference.fsti"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | fact: Steel.Memory.stable_property pcm -> v: FStar.Ghost.erased a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.PCM.pcm",
"Steel.Memory.stable_property",
"FStar.Ghost.erased",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.PCM.compatible",
"FStar.Ghost.reveal"
] | [] | false | false | false | false | true | let fact_valid_compat (#a: Type) (#pcm: pcm a) (fact: stable_property pcm) (v: erased a) =
| squash (forall z. compatible pcm v z ==> fact z) | false |
|
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.block_length_smaller_than_max_input | val block_length_smaller_than_max_input (a:hash_alg) :
Lemma (block_length a `less_than_max_input_length` a) | val block_length_smaller_than_max_input (a:hash_alg) :
Lemma (block_length a `less_than_max_input_length` a) | let block_length_smaller_than_max_input (a:hash_alg) =
normalize_term_spec(pow2 61 - 1);
normalize_term_spec(pow2 125 - 1);
normalize_term_spec(pow2 64 - 1) | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 210,
"start_col": 0,
"start_line": 207
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50"
let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h
let update_multi_zero_blake a prevlen h =
Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h
#pop-options
#push-options "--fuel 1"
let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input) == (update a h input))
=
let h1 = update_multi a h () input in
assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input);
if S.length input = 0 then
begin
assert(h1 == h)
end
else
begin
let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in
let h2 = update a h block in
assert(rem `Seq.equal` Seq.empty);
assert(block `Seq.equal` input);
let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in
assert(h1 == h3)
end
#pop-options
let update_multi_associative (a: hash_alg{not (is_blake a)})
(h: words_state a)
(input1: bytes)
(input2: bytes):
Lemma
(requires
S.length input1 % block_length a == 0 /\
S.length input2 % block_length a == 0)
(ensures (
let input = S.append input1 input2 in
S.length input % block_length a == 0 /\
update_multi a (update_multi a h () input1) () input2 == update_multi a h () input))
= match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a /8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
let input = input1 `S.append` input2 in
assert (input1 `S.equal` S.slice input 0 (S.length input1));
assert (input2 `S.equal` S.slice input (S.length input1) (S.length input));
Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h
let lemma_blocki_aux1 (a:blake_alg) (s1 s2:bytes) (i:nat{i < S.length s1 / block_length a})
: Lemma (Spec.Blake2.get_blocki (to_blake_alg a) s1 i == Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
= assert (Spec.Blake2.get_blocki (to_blake_alg a) s1 i `S.equal` Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
#push-options "--fuel 0 --ifuel 0 --z3rlimit 300"
open FStar.Mul
let lemma_blocki_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (i:nat{i < nb2})
: Lemma
(requires
S.length s1 == nb1 * block_length a /\
S.length s2 == nb2 * block_length a)
(ensures Spec.Blake2.get_blocki (to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1))
= let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
calc (==) {
Spec.Blake2.get_blocki a' s (i + nb1);
(==) { }
S.slice s ((i + nb1) * block_length a) ((i + nb1 + 1) * block_length a);
(==) { }
S.slice s (i * block_length a + nb1 * block_length a) ((i + 1) * block_length a + nb1 * block_length a);
(==) { }
S.slice s (i * block_length a + S.length s1) ((i + 1) * block_length a + S.length s1);
(==) { S.slice_slice s (S.length s1) (S.length s) (i * block_length a) ((i+1) * block_length a) }
S.slice (S.slice s (S.length s1) (S.length s)) (i * block_length a) ((i+1) * block_length a);
(==) { S.append_slices s1 s2; assert (s2 `S.equal` S.slice s (S.length s1) (S.length s)) }
S.slice s2 (i * block_length a) ((i+1) * block_length a);
(==) { }
Spec.Blake2.get_blocki a' s2 i;
}
let lemma_update_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (prevlen1 prevlen2:nat) (i:nat{i < nb2}) (acc:words_state a)
: Lemma
(requires
S.length s1 == nb1 * block_length a /\
S.length s2 == nb2 * block_length a /\
prevlen1 % block_length a == 0 /\
prevlen2 = prevlen1 + S.length s1 /\
(S.length (S.append s1 s2) + prevlen1) `less_than_max_input_length` a)
(ensures
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen1 (s1 `S.append` s2) (i + nb1) acc ==
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen2 s2 i acc)
= let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
let open Spec.Blake2 in
let f1 = blake2_update1 (to_blake_alg a) prevlen1 s in
let f2 = blake2_update1 (to_blake_alg a) prevlen2 s2 in
let totlen1 = prevlen1 + (i + nb1 + 1) * size_block a' in
let totlen2 = prevlen2 + (i + 1) * size_block a' in
// Proving totlen1 == totlen2 for the last calc step below
calc (==) {
totlen2;
(==) { }
prevlen2 + (i + 1) * block_length a;
(==) { }
prevlen1 + S.length s1 + (i + 1) * block_length a;
(==) { }
prevlen1 + nb1 * block_length a + (i + 1) * block_length a;
(==) { Math.Lemmas.distributivity_add_left (i + 1) nb1 (block_length a) }
prevlen1 + (i + 1 + nb1) * block_length a;
(==) { }
totlen1;
};
calc (==) {
f1 (i + nb1) acc;
(==) { }
blake2_update_block a' false totlen1 (get_blocki a' s (i + nb1)) acc;
(==) { lemma_blocki_aux2 a s1 s2 nb1 nb2 i }
blake2_update_block a' false totlen1 (get_blocki a' s2 i) acc;
(==) { }
f2 i acc;
}
let update_multi_associative_blake (a: blake_alg)
(h: words_state a)
(prevlen1: nat)
(prevlen2: nat)
(input1: bytes)
(input2: bytes):
Lemma
(requires (
prevlen1 % block_length a == 0 /\
S.length input1 % block_length a == 0 /\
S.length input2 % block_length a == 0 /\
prevlen2 = prevlen1 + S.length input1 /\
update_multi_pre a prevlen1 (S.append input1 input2)))
(ensures (
let input = S.append input1 input2 in
S.length input % block_length a == 0 /\
update_multi_pre a prevlen1 input1 /\
update_multi_pre a prevlen2 input2 /\
update_multi a (update_multi a h prevlen1 input1) prevlen2 input2 == update_multi a h prevlen1 input))
= let input = S.append input1 input2 in
let nb1 = S.length input1 / block_length a in
let nb2 = S.length input2 / block_length a in
let nb = S.length input / block_length a in
let a' = to_blake_alg a in
let f = Spec.Blake2.blake2_update1 a' prevlen1 input in
let f1 = Spec.Blake2.blake2_update1 a' prevlen1 input1 in
let f2 = Spec.Blake2.blake2_update1 a' prevlen2 input2 in
let aux1 (i:nat{i < nb1}) (acc:words_state a) : Lemma (f i acc == f1 i acc)
= lemma_blocki_aux1 a input1 input2 i
in
let open FStar.Mul in
let aux2 (i:nat{i < nb2}) (acc:words_state a) : Lemma (f (i + nb1) acc == f2 i acc)
= lemma_update_aux2 a input1 input2 nb1 nb2 prevlen1 prevlen2 i acc
in
let open Lib.LoopCombinators in
let open Lib.Sequence.Lemmas in
let fix = fixed_a (words_state a) in
calc (==) {
update_multi a h prevlen1 input;
(==) { }
repeati #(words_state a) nb f h;
(==) { repeati_def nb f h }
repeat_right 0 nb fix f h;
(==) { repeat_right_plus 0 nb1 nb fix f h; repeati_def nb1 f h }
repeat_right nb1 nb fix f (repeati nb1 f h);
(==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f f1 h }
repeat_right nb1 nb fix f (update_multi a h prevlen1 input1);
(==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 fix fix f2 f (update_multi a h prevlen1 input1) }
repeat_right 0 nb2 fix f2 (update_multi a h prevlen1 input1);
(==) { repeati_def nb2 f2 (update_multi a h prevlen1 input1) }
update_multi a (update_multi a h prevlen1 input1) prevlen2 input2;
} | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg
-> FStar.Pervasives.Lemma
(ensures
Spec.Hash.Definitions.less_than_max_input_length (Spec.Hash.Definitions.block_length a) a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"FStar.Pervasives.normalize_term_spec",
"Prims.int",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.unit"
] | [] | true | false | true | false | false | let block_length_smaller_than_max_input (a: hash_alg) =
| normalize_term_spec (pow2 61 - 1);
normalize_term_spec (pow2 125 - 1);
normalize_term_spec (pow2 64 - 1) | false |
Hacl.Chacha20.Vec128.fst | Hacl.Chacha20.Vec128.double_round_128 | val double_round_128 : Hacl.Meta.Chacha20.Vec.core32xn_double_round_higher_t Prims.l_True | let double_round_128 = core32xn_double_round_higher #4 True | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 7,
"start_col": 0,
"start_line": 7
} | module Hacl.Chacha20.Vec128
open Hacl.Meta.Chacha20.Vec
[@CInline] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec128.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.core32xn_double_round_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.core32xn_double_round_higher",
"Prims.l_True"
] | [] | false | false | false | false | false | let double_round_128 =
| core32xn_double_round_higher #4 True | false |
|
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.lemma_blocki_aux1 | val lemma_blocki_aux1 (a: blake_alg) (s1 s2: bytes) (i: nat{i < S.length s1 / block_length a})
: Lemma
(Spec.Blake2.get_blocki (to_blake_alg a) s1 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i) | val lemma_blocki_aux1 (a: blake_alg) (s1 s2: bytes) (i: nat{i < S.length s1 / block_length a})
: Lemma
(Spec.Blake2.get_blocki (to_blake_alg a) s1 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i) | let lemma_blocki_aux1 (a:blake_alg) (s1 s2:bytes) (i:nat{i < S.length s1 / block_length a})
: Lemma (Spec.Blake2.get_blocki (to_blake_alg a) s1 i == Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
= assert (Spec.Blake2.get_blocki (to_blake_alg a) s1 i `S.equal` Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i) | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 126,
"end_line": 77,
"start_col": 0,
"start_line": 75
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50"
let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h
let update_multi_zero_blake a prevlen h =
Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h
#pop-options
#push-options "--fuel 1"
let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input) == (update a h input))
=
let h1 = update_multi a h () input in
assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input);
if S.length input = 0 then
begin
assert(h1 == h)
end
else
begin
let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in
let h2 = update a h block in
assert(rem `Seq.equal` Seq.empty);
assert(block `Seq.equal` input);
let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in
assert(h1 == h3)
end
#pop-options
let update_multi_associative (a: hash_alg{not (is_blake a)})
(h: words_state a)
(input1: bytes)
(input2: bytes):
Lemma
(requires
S.length input1 % block_length a == 0 /\
S.length input2 % block_length a == 0)
(ensures (
let input = S.append input1 input2 in
S.length input % block_length a == 0 /\
update_multi a (update_multi a h () input1) () input2 == update_multi a h () input))
= match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a /8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
let input = input1 `S.append` input2 in
assert (input1 `S.equal` S.slice input 0 (S.length input1));
assert (input2 `S.equal` S.slice input (S.length input1) (S.length input));
Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.blake_alg ->
s1: Spec.Hash.Definitions.bytes ->
s2: Spec.Hash.Definitions.bytes ->
i: Prims.nat{i < FStar.Seq.Base.length s1 / Spec.Hash.Definitions.block_length a}
-> FStar.Pervasives.Lemma
(ensures
Spec.Blake2.get_blocki (Spec.Hash.Definitions.to_blake_alg a) s1 i ==
Spec.Blake2.get_blocki (Spec.Hash.Definitions.to_blake_alg a) (FStar.Seq.Base.append s1 s2) i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.blake_alg",
"Spec.Hash.Definitions.bytes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.block_length",
"Prims._assert",
"FStar.Seq.Base.equal",
"Spec.Blake2.get_blocki",
"Spec.Hash.Definitions.to_blake_alg",
"FStar.Seq.Base.append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Spec.Blake2.Definitions.block_s",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_blocki_aux1 (a: blake_alg) (s1 s2: bytes) (i: nat{i < S.length s1 / block_length a})
: Lemma
(Spec.Blake2.get_blocki (to_blake_alg a) s1 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i) =
| assert ((Spec.Blake2.get_blocki (to_blake_alg a) s1 i)
`S.equal`
(Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)) | false |
Hacl.Chacha20.Vec128.fst | Hacl.Chacha20.Vec128.chacha20_encrypt_128 | val chacha20_encrypt_128 : Hacl.Meta.Chacha20.Vec.vec_chacha20_encrypt_higher_t Prims.l_True | let chacha20_encrypt_128 = vec_chacha20_encrypt_higher #4 True chacha20_init_128 chacha20_core_128 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Hacl.Chacha20.Vec128
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_128 = core32xn_double_round_higher #4 True
[@CInline]
private
let chacha20_core_128 = vec_chacha20_core_higher #4 True double_round_128
[@CInline]
private
let chacha20_init_128 = Hacl.Impl.Chacha20.Vec.chacha20_init #4 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec128.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_encrypt_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_encrypt_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec128.chacha20_init_128",
"Hacl.Chacha20.Vec128.chacha20_core_128"
] | [] | false | false | false | false | false | let chacha20_encrypt_128 =
| vec_chacha20_encrypt_higher #4 True chacha20_init_128 chacha20_core_128 | false |
|
Hacl.Chacha20.Vec128.fst | Hacl.Chacha20.Vec128.chacha20_decrypt_128 | val chacha20_decrypt_128 : Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher_t Prims.l_True | let chacha20_decrypt_128 = vec_chacha20_decrypt_higher #4 True chacha20_init_128 chacha20_core_128 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 16,
"start_col": 0,
"start_line": 16
} | module Hacl.Chacha20.Vec128
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_128 = core32xn_double_round_higher #4 True
[@CInline]
private
let chacha20_core_128 = vec_chacha20_core_higher #4 True double_round_128
[@CInline]
private
let chacha20_init_128 = Hacl.Impl.Chacha20.Vec.chacha20_init #4 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec128.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec128.chacha20_init_128",
"Hacl.Chacha20.Vec128.chacha20_core_128"
] | [] | false | false | false | false | false | let chacha20_decrypt_128 =
| vec_chacha20_decrypt_higher #4 True chacha20_init_128 chacha20_core_128 | false |
|
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.update_multi_zero_blake | val update_multi_zero_blake (a: hash_alg { is_blake a } ) (prevlen: extra_state a) (h: words_state a): Lemma
(requires (update_multi_pre a prevlen S.empty))
(ensures (update_multi a h prevlen S.empty == h)) | val update_multi_zero_blake (a: hash_alg { is_blake a } ) (prevlen: extra_state a) (h: words_state a): Lemma
(requires (update_multi_pre a prevlen S.empty))
(ensures (update_multi a h prevlen S.empty == h)) | let update_multi_zero_blake a prevlen h =
Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 118,
"end_line": 28,
"start_col": 0,
"start_line": 27
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50"
let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.hash_alg{Spec.Hash.Definitions.is_blake a} ->
prevlen: Spec.Hash.Definitions.extra_state a ->
h: Spec.Hash.Definitions.words_state a
-> FStar.Pervasives.Lemma
(requires Spec.Agile.Hash.update_multi_pre a prevlen FStar.Seq.Base.empty)
(ensures Spec.Agile.Hash.update_multi a h prevlen FStar.Seq.Base.empty == h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.b2t",
"Spec.Hash.Definitions.is_blake",
"Spec.Hash.Definitions.extra_state",
"Spec.Hash.Definitions.words_state",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Blake2.Definitions.state",
"Spec.Hash.Definitions.to_blake_alg",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Spec.Blake2.blake2_update1",
"FStar.Seq.Base.empty",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit"
] | [] | true | false | true | false | false | let update_multi_zero_blake a prevlen h =
| Lib.LoopCombinators.eq_repeati0 (0 / block_length a)
(Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty)
h | false |
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.update_multi_update | val update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input == update a h input)) | val update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input == update a h input)) | let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input) == (update a h input))
=
let h1 = update_multi a h () input in
assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input);
if S.length input = 0 then
begin
assert(h1 == h)
end
else
begin
let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in
let h2 = update a h block in
assert(rem `Seq.equal` Seq.empty);
assert(block `Seq.equal` input);
let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in
assert(h1 == h3)
end | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 49,
"start_col": 0,
"start_line": 32
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50"
let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h
let update_multi_zero_blake a prevlen h =
Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h
#pop-options | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.md_alg ->
h: Spec.Hash.Definitions.words_state a ->
input: Spec.Hash.Definitions.bytes_block a
-> FStar.Pervasives.Lemma
(ensures Spec.Agile.Hash.update_multi a h () input == Spec.Agile.Hash.update a h input) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.md_alg",
"Spec.Hash.Definitions.words_state",
"Spec.Hash.Definitions.bytes_block",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint8",
"Prims._assert",
"Prims.eq2",
"Prims.bool",
"FStar.Seq.Base.seq",
"Lib.UpdateMulti.uint8",
"Lib.UpdateMulti.mk_update_multi",
"Spec.Hash.Definitions.block_length",
"Spec.Agile.Hash.update",
"Prims.unit",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.empty",
"FStar.Pervasives.Native.tuple2",
"Lib.UpdateMulti.split_block",
"Spec.Agile.Hash.update_multi",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a)
: Lemma (ensures (update_multi a h () input) == (update a h input)) =
| let h1 = update_multi a h () input in
assert (h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input);
if S.length input = 0
then assert (h1 == h)
else
let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in
let h2 = update a h block in
assert (rem `Seq.equal` Seq.empty);
assert (block `Seq.equal` input);
let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in
assert (h1 == h3) | false |
Hacl.Chacha20.Vec128.fst | Hacl.Chacha20.Vec128.chacha20_init_128 | val chacha20_init_128 : ctx: Hacl.Impl.Chacha20.Core32xN.state 4 ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul ->
ctr0: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | let chacha20_init_128 = Hacl.Impl.Chacha20.Vec.chacha20_init #4 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Hacl.Chacha20.Vec128
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_128 = core32xn_double_round_higher #4 True
[@CInline]
private
let chacha20_core_128 = vec_chacha20_core_higher #4 True double_round_128
[@CInline] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec128.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ctx: Hacl.Impl.Chacha20.Core32xN.state 4 ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul ->
ctr0: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Vec.chacha20_init"
] | [] | false | true | false | false | false | let chacha20_init_128 =
| Hacl.Impl.Chacha20.Vec.chacha20_init #4 | false |
|
FStar.Tactics.Canon.fst | FStar.Tactics.Canon.step_lemma | val step_lemma (lem: term) : Tac unit | val step_lemma (lem: term) : Tac unit | let step_lemma (lem : term) : Tac unit =
step (fun () -> apply_lemma lem) | {
"file_name": "ulib/FStar.Tactics.Canon.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 131,
"start_col": 0,
"start_line": 130
} | (*
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 FStar.Tactics.Canon
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.Reflection.V2.Arith
open FStar.Mul
module O = FStar.Order
private
val distr : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y + z) == x * y + x * z)
private
let distr #x #y #z = ()
private
val distl : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) * z == x * z + y * z)
private
let distl #x #y #z = ()
private
val ass_plus_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x + (y + z) == (x + y) + z)
private
let ass_plus_l #x #y #z = ()
private
val ass_mult_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y * z) == (x * y) * z)
private
let ass_mult_l #x #y #z = ()
private
val comm_plus : (#x : int) -> (#y : int) -> Lemma (x + y == y + x)
private
let comm_plus #x #y = ()
private
val sw_plus : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) + z == (x + z) + y)
private
let sw_plus #x #y #z = ()
private
val sw_mult : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x * y) * z == (x * z) * y)
private
let sw_mult #x #y #z = ()
private
val comm_mult : (#x : int) -> (#y : int) -> Lemma (x * y == y * x)
private
let comm_mult #x #y = ()
private
val trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) ->
squash (x == y) -> squash (y == z) -> Lemma (x == z)
private
let trans #a #x #z #y e1 e2 = ()
private
val cong_plus : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w + x == y + z)
private
let cong_plus #w #x #y #z p q = ()
private
val cong_mult : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w * x == y * z)
private
let cong_mult #w #x #y #z p q = ()
private
val neg_minus_one : (#x:int) -> Lemma (-x == (-1) * x)
private
let neg_minus_one #x = ()
private
val x_plus_zero : (#x:int) -> Lemma (x + 0 == x)
private
let x_plus_zero #x = ()
private
val zero_plus_x : (#x:int) -> Lemma (0 + x == x)
private
let zero_plus_x #x = ()
private
val x_mult_zero : (#x:int) -> Lemma (x * 0 == 0)
private
let x_mult_zero #x = ()
private
val zero_mult_x : (#x:int) -> Lemma (0 * x == 0)
private
let zero_mult_x #x = ()
private
val x_mult_one : (#x:int) -> Lemma (x * 1 == x)
private
let x_mult_one #x = ()
private
val one_mult_x : (#x:int) -> Lemma (1 * x == x)
private
let one_mult_x #x = ()
private
val minus_is_plus : (#x : int) -> (#y : int) -> Lemma (x - y == x + (-y))
private
let minus_is_plus #x #y = ()
private
let step (t : unit -> Tac unit) : Tac unit =
apply_lemma (`trans);
t () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.Arith.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Canon.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Order",
"short_module": "O"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Arith",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | lem: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.Canon.step",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let step_lemma (lem: term) : Tac unit =
| step (fun () -> apply_lemma lem) | false |
Hacl.Chacha20.Vec128.fst | Hacl.Chacha20.Vec128.chacha20_core_128 | val chacha20_core_128 : Hacl.Meta.Chacha20.Vec.vec_chacha20_core_higher_t Prims.l_True | let chacha20_core_128 = vec_chacha20_core_higher #4 True double_round_128 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 10,
"start_col": 0,
"start_line": 10
} | module Hacl.Chacha20.Vec128
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_128 = core32xn_double_round_higher #4 True
[@CInline] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec128.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_core_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_core_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec128.double_round_128"
] | [] | false | false | false | false | false | let chacha20_core_128 =
| vec_chacha20_core_higher #4 True double_round_128 | false |
|
FStar.Tactics.Canon.fst | FStar.Tactics.Canon.step | val step (t: (unit -> Tac unit)) : Tac unit | val step (t: (unit -> Tac unit)) : Tac unit | let step (t : unit -> Tac unit) : Tac unit =
apply_lemma (`trans);
t () | {
"file_name": "ulib/FStar.Tactics.Canon.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 8,
"end_line": 127,
"start_col": 0,
"start_line": 125
} | (*
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 FStar.Tactics.Canon
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.Reflection.V2.Arith
open FStar.Mul
module O = FStar.Order
private
val distr : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y + z) == x * y + x * z)
private
let distr #x #y #z = ()
private
val distl : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) * z == x * z + y * z)
private
let distl #x #y #z = ()
private
val ass_plus_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x + (y + z) == (x + y) + z)
private
let ass_plus_l #x #y #z = ()
private
val ass_mult_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y * z) == (x * y) * z)
private
let ass_mult_l #x #y #z = ()
private
val comm_plus : (#x : int) -> (#y : int) -> Lemma (x + y == y + x)
private
let comm_plus #x #y = ()
private
val sw_plus : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) + z == (x + z) + y)
private
let sw_plus #x #y #z = ()
private
val sw_mult : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x * y) * z == (x * z) * y)
private
let sw_mult #x #y #z = ()
private
val comm_mult : (#x : int) -> (#y : int) -> Lemma (x * y == y * x)
private
let comm_mult #x #y = ()
private
val trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) ->
squash (x == y) -> squash (y == z) -> Lemma (x == z)
private
let trans #a #x #z #y e1 e2 = ()
private
val cong_plus : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w + x == y + z)
private
let cong_plus #w #x #y #z p q = ()
private
val cong_mult : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w * x == y * z)
private
let cong_mult #w #x #y #z p q = ()
private
val neg_minus_one : (#x:int) -> Lemma (-x == (-1) * x)
private
let neg_minus_one #x = ()
private
val x_plus_zero : (#x:int) -> Lemma (x + 0 == x)
private
let x_plus_zero #x = ()
private
val zero_plus_x : (#x:int) -> Lemma (0 + x == x)
private
let zero_plus_x #x = ()
private
val x_mult_zero : (#x:int) -> Lemma (x * 0 == 0)
private
let x_mult_zero #x = ()
private
val zero_mult_x : (#x:int) -> Lemma (0 * x == 0)
private
let zero_mult_x #x = ()
private
val x_mult_one : (#x:int) -> Lemma (x * 1 == x)
private
let x_mult_one #x = ()
private
val one_mult_x : (#x:int) -> Lemma (1 * x == x)
private
let one_mult_x #x = ()
private
val minus_is_plus : (#x : int) -> (#y : int) -> Lemma (x - y == x + (-y))
private
let minus_is_plus #x #y = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.Arith.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Canon.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Order",
"short_module": "O"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Arith",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let step (t: (unit -> Tac unit)) : Tac unit =
| apply_lemma (`trans);
t () | false |
FStar.Tactics.Canon.fst | FStar.Tactics.Canon.canon | val canon: Prims.unit -> Tac unit | val canon: Prims.unit -> Tac unit | let canon () : Tac unit =
pointwise canon_point_entry | {
"file_name": "ulib/FStar.Tactics.Canon.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 281,
"start_col": 0,
"start_line": 280
} | (*
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 FStar.Tactics.Canon
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.Reflection.V2.Arith
open FStar.Mul
module O = FStar.Order
private
val distr : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y + z) == x * y + x * z)
private
let distr #x #y #z = ()
private
val distl : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) * z == x * z + y * z)
private
let distl #x #y #z = ()
private
val ass_plus_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x + (y + z) == (x + y) + z)
private
let ass_plus_l #x #y #z = ()
private
val ass_mult_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y * z) == (x * y) * z)
private
let ass_mult_l #x #y #z = ()
private
val comm_plus : (#x : int) -> (#y : int) -> Lemma (x + y == y + x)
private
let comm_plus #x #y = ()
private
val sw_plus : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) + z == (x + z) + y)
private
let sw_plus #x #y #z = ()
private
val sw_mult : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x * y) * z == (x * z) * y)
private
let sw_mult #x #y #z = ()
private
val comm_mult : (#x : int) -> (#y : int) -> Lemma (x * y == y * x)
private
let comm_mult #x #y = ()
private
val trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) ->
squash (x == y) -> squash (y == z) -> Lemma (x == z)
private
let trans #a #x #z #y e1 e2 = ()
private
val cong_plus : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w + x == y + z)
private
let cong_plus #w #x #y #z p q = ()
private
val cong_mult : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w * x == y * z)
private
let cong_mult #w #x #y #z p q = ()
private
val neg_minus_one : (#x:int) -> Lemma (-x == (-1) * x)
private
let neg_minus_one #x = ()
private
val x_plus_zero : (#x:int) -> Lemma (x + 0 == x)
private
let x_plus_zero #x = ()
private
val zero_plus_x : (#x:int) -> Lemma (0 + x == x)
private
let zero_plus_x #x = ()
private
val x_mult_zero : (#x:int) -> Lemma (x * 0 == 0)
private
let x_mult_zero #x = ()
private
val zero_mult_x : (#x:int) -> Lemma (0 * x == 0)
private
let zero_mult_x #x = ()
private
val x_mult_one : (#x:int) -> Lemma (x * 1 == x)
private
let x_mult_one #x = ()
private
val one_mult_x : (#x:int) -> Lemma (1 * x == x)
private
let one_mult_x #x = ()
private
val minus_is_plus : (#x : int) -> (#y : int) -> Lemma (x - y == x + (-y))
private
let minus_is_plus #x #y = ()
private
let step (t : unit -> Tac unit) : Tac unit =
apply_lemma (`trans);
t ()
private
let step_lemma (lem : term) : Tac unit =
step (fun () -> apply_lemma lem)
private val canon_point : expr -> Tac expr
private let rec canon_point e =
let skip () : Tac expr =
trefl (); e
in
match e with
// Evaluate constants
| Plus (Lit a) (Lit b) ->
norm [primops];
trefl ();
Lit (a + b)
| Mult (Lit a) (Lit b) ->
norm [delta; primops]; // Need delta to turn op_Star into op_Multiply, as there's no primop for it
trefl ();
Lit (a * b)
// Forget about negations
| Neg e ->
step_lemma (`neg_minus_one);
canon_point (Mult (Lit (-1)) e)
// Distribute
| Mult a (Plus b c) ->
step_lemma (`distr);
step_lemma (`cong_plus);
let l = canon_point (Mult a b) in
let r = canon_point (Mult a c) in
canon_point (Plus l r)
| Mult (Plus a b) c ->
step_lemma (`distl);
step_lemma (`cong_plus);
let l = canon_point (Mult a c) in
let r = canon_point (Mult b c) in
canon_point (Plus l r)
// Associate to the left
| Mult a (Mult b c) ->
step_lemma (`ass_mult_l);
step_lemma (`cong_mult);
let l = canon_point (Mult a b) in
let r = canon_point c in
canon_point (Mult l r)
| Plus a (Plus b c) ->
step_lemma (`ass_plus_l);
step_lemma (`cong_plus);
let l = canon_point (Plus a b) in
let r = canon_point c in
canon_point (Plus l r)
| Plus (Plus a b) c ->
if O.gt (compare_expr b c)
then begin
step_lemma (`sw_plus);
apply_lemma (`cong_plus);
let l = canon_point (Plus a c) in
trefl() ;
Plus l b
end
else skip ()
| Mult (Mult a b) c ->
if O.gt (compare_expr b c)
then begin
step_lemma (`sw_mult);
apply_lemma (`cong_mult);
let l = canon_point (Mult a c) in
trefl ();
Mult l b
end
else skip ()
| Plus a (Lit 0) ->
apply_lemma (`x_plus_zero);
a
| Plus (Lit 0) b ->
apply_lemma (`zero_plus_x);
b
| Plus a b ->
if O.gt (compare_expr a b)
then (apply_lemma (`comm_plus); Plus b a)
else skip ()
| Mult (Lit 0) _ ->
apply_lemma (`zero_mult_x);
Lit 0
| Mult _ (Lit 0) ->
apply_lemma (`x_mult_zero);
Lit 0
| Mult (Lit 1) r ->
apply_lemma (`one_mult_x);
r
| Mult l (Lit 1) ->
apply_lemma (`x_mult_one);
l
| Mult a b ->
if O.gt (compare_expr a b)
then (apply_lemma (`comm_mult); Mult b a)
else skip ()
// Forget about subtraction
| Minus a b ->
step_lemma (`minus_is_plus);
step_lemma (`cong_plus);
trefl ();
let negb = match b with | Lit n -> Lit (-n) | _ -> Neg b in
// ^ We need to take care wrt literals, since an application (- N)
// will get reduced to the literal -N and then neg_minus_one will not
// apply.
let r = canon_point negb in
canon_point (Plus a r)
| _ ->
skip ()
// On canon_point_entry, we interpret the LHS of the goal as an
// arithmetic expression, of which we keep track in canon_point so we
// avoid reinterpreting the goal, which gives a good speedup.
//
// However, we are repeating work between canon_point_entry calls, since
// in (L + R), we are called once for L, once for R, and once for the
// sum which traverses both (their canonized forms, actually).
//
// The proper way to solve this is have some state-passing in pointwise,
// maybe having the inner tactic be of type (list a -> tactic a), where
// the list is the collected results for all child calls.
let canon_point_entry () : Tac unit =
norm [primops];
let g = cur_goal () in
match term_as_formula g with
| Comp (Eq _) l r ->
begin match run_tm (is_arith_expr l) with
| Inr e -> (let _e = canon_point e in ())
| Inl _ -> trefl ()
end
| _ ->
fail ("impossible: " ^ term_to_string g) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.Arith.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Canon.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Order",
"short_module": "O"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Arith",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.pointwise",
"FStar.Tactics.Canon.canon_point_entry"
] | [] | false | true | false | false | false | let canon () : Tac unit =
| pointwise canon_point_entry | false |
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.update_multi_zero | val update_multi_zero (a: hash_alg { not (is_blake a)} ) (h: words_state a): Lemma
(ensures (update_multi a h () S.empty == h)) | val update_multi_zero (a: hash_alg { not (is_blake a)} ) (h: words_state a): Lemma
(ensures (update_multi a h () S.empty == h)) | let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 25,
"start_col": 0,
"start_line": 15
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50" | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.hash_alg{Prims.op_Negation (Spec.Hash.Definitions.is_blake a)} ->
h: Spec.Hash.Definitions.words_state a
-> FStar.Pervasives.Lemma (ensures Spec.Agile.Hash.update_multi a h () FStar.Seq.Base.empty == h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.b2t",
"Prims.op_Negation",
"Spec.Hash.Definitions.is_blake",
"Spec.Hash.Definitions.words_state",
"Lib.UpdateMulti.update_multi_zero",
"Spec.Hash.Definitions.block_length",
"Spec.Agile.Hash.update",
"Lib.LoopCombinators.eq_repeati0",
"Spec.SHA3.state",
"Lib.Sequence.repeat_blocks_f",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.empty",
"Prims.int",
"Prims.op_Division",
"Prims.unit",
"Lib.Sequence.lemma_repeat_blocks_multi",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Spec.SHA3.absorb_inner",
"Spec.Hash.Definitions.rate"
] | [] | false | false | true | false | false | let update_multi_zero a h =
| match a with
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512 -> Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h | false |
FStar.Tactics.Canon.fst | FStar.Tactics.Canon.canon_point | val canon_point : expr -> Tac expr | val canon_point : expr -> Tac expr | let rec canon_point e =
let skip () : Tac expr =
trefl (); e
in
match e with
// Evaluate constants
| Plus (Lit a) (Lit b) ->
norm [primops];
trefl ();
Lit (a + b)
| Mult (Lit a) (Lit b) ->
norm [delta; primops]; // Need delta to turn op_Star into op_Multiply, as there's no primop for it
trefl ();
Lit (a * b)
// Forget about negations
| Neg e ->
step_lemma (`neg_minus_one);
canon_point (Mult (Lit (-1)) e)
// Distribute
| Mult a (Plus b c) ->
step_lemma (`distr);
step_lemma (`cong_plus);
let l = canon_point (Mult a b) in
let r = canon_point (Mult a c) in
canon_point (Plus l r)
| Mult (Plus a b) c ->
step_lemma (`distl);
step_lemma (`cong_plus);
let l = canon_point (Mult a c) in
let r = canon_point (Mult b c) in
canon_point (Plus l r)
// Associate to the left
| Mult a (Mult b c) ->
step_lemma (`ass_mult_l);
step_lemma (`cong_mult);
let l = canon_point (Mult a b) in
let r = canon_point c in
canon_point (Mult l r)
| Plus a (Plus b c) ->
step_lemma (`ass_plus_l);
step_lemma (`cong_plus);
let l = canon_point (Plus a b) in
let r = canon_point c in
canon_point (Plus l r)
| Plus (Plus a b) c ->
if O.gt (compare_expr b c)
then begin
step_lemma (`sw_plus);
apply_lemma (`cong_plus);
let l = canon_point (Plus a c) in
trefl() ;
Plus l b
end
else skip ()
| Mult (Mult a b) c ->
if O.gt (compare_expr b c)
then begin
step_lemma (`sw_mult);
apply_lemma (`cong_mult);
let l = canon_point (Mult a c) in
trefl ();
Mult l b
end
else skip ()
| Plus a (Lit 0) ->
apply_lemma (`x_plus_zero);
a
| Plus (Lit 0) b ->
apply_lemma (`zero_plus_x);
b
| Plus a b ->
if O.gt (compare_expr a b)
then (apply_lemma (`comm_plus); Plus b a)
else skip ()
| Mult (Lit 0) _ ->
apply_lemma (`zero_mult_x);
Lit 0
| Mult _ (Lit 0) ->
apply_lemma (`x_mult_zero);
Lit 0
| Mult (Lit 1) r ->
apply_lemma (`one_mult_x);
r
| Mult l (Lit 1) ->
apply_lemma (`x_mult_one);
l
| Mult a b ->
if O.gt (compare_expr a b)
then (apply_lemma (`comm_mult); Mult b a)
else skip ()
// Forget about subtraction
| Minus a b ->
step_lemma (`minus_is_plus);
step_lemma (`cong_plus);
trefl ();
let negb = match b with | Lit n -> Lit (-n) | _ -> Neg b in
// ^ We need to take care wrt literals, since an application (- N)
// will get reduced to the literal -N and then neg_minus_one will not
// apply.
let r = canon_point negb in
canon_point (Plus a r)
| _ ->
skip () | {
"file_name": "ulib/FStar.Tactics.Canon.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 15,
"end_line": 254,
"start_col": 8,
"start_line": 134
} | (*
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 FStar.Tactics.Canon
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.Reflection.V2.Arith
open FStar.Mul
module O = FStar.Order
private
val distr : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y + z) == x * y + x * z)
private
let distr #x #y #z = ()
private
val distl : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) * z == x * z + y * z)
private
let distl #x #y #z = ()
private
val ass_plus_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x + (y + z) == (x + y) + z)
private
let ass_plus_l #x #y #z = ()
private
val ass_mult_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y * z) == (x * y) * z)
private
let ass_mult_l #x #y #z = ()
private
val comm_plus : (#x : int) -> (#y : int) -> Lemma (x + y == y + x)
private
let comm_plus #x #y = ()
private
val sw_plus : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) + z == (x + z) + y)
private
let sw_plus #x #y #z = ()
private
val sw_mult : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x * y) * z == (x * z) * y)
private
let sw_mult #x #y #z = ()
private
val comm_mult : (#x : int) -> (#y : int) -> Lemma (x * y == y * x)
private
let comm_mult #x #y = ()
private
val trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) ->
squash (x == y) -> squash (y == z) -> Lemma (x == z)
private
let trans #a #x #z #y e1 e2 = ()
private
val cong_plus : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w + x == y + z)
private
let cong_plus #w #x #y #z p q = ()
private
val cong_mult : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w * x == y * z)
private
let cong_mult #w #x #y #z p q = ()
private
val neg_minus_one : (#x:int) -> Lemma (-x == (-1) * x)
private
let neg_minus_one #x = ()
private
val x_plus_zero : (#x:int) -> Lemma (x + 0 == x)
private
let x_plus_zero #x = ()
private
val zero_plus_x : (#x:int) -> Lemma (0 + x == x)
private
let zero_plus_x #x = ()
private
val x_mult_zero : (#x:int) -> Lemma (x * 0 == 0)
private
let x_mult_zero #x = ()
private
val zero_mult_x : (#x:int) -> Lemma (0 * x == 0)
private
let zero_mult_x #x = ()
private
val x_mult_one : (#x:int) -> Lemma (x * 1 == x)
private
let x_mult_one #x = ()
private
val one_mult_x : (#x:int) -> Lemma (1 * x == x)
private
let one_mult_x #x = ()
private
val minus_is_plus : (#x : int) -> (#y : int) -> Lemma (x - y == x + (-y))
private
let minus_is_plus #x #y = ()
private
let step (t : unit -> Tac unit) : Tac unit =
apply_lemma (`trans);
t ()
private
let step_lemma (lem : term) : Tac unit =
step (fun () -> apply_lemma lem) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.Arith.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Canon.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Order",
"short_module": "O"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Arith",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Reflection.V2.Arith.expr -> FStar.Tactics.Effect.Tac FStar.Reflection.V2.Arith.expr | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Reflection.V2.Arith.expr",
"Prims.int",
"FStar.Reflection.V2.Arith.Lit",
"Prims.op_Addition",
"Prims.unit",
"FStar.Tactics.V2.Derived.trefl",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.primops",
"Prims.Nil",
"FStar.Mul.op_Star",
"FStar.Pervasives.delta",
"FStar.Tactics.Canon.canon_point",
"FStar.Reflection.V2.Arith.Mult",
"Prims.op_Minus",
"FStar.Tactics.Canon.step_lemma",
"FStar.Reflection.V2.Arith.Plus",
"FStar.Order.gt",
"FStar.Reflection.V2.Arith.compare_expr",
"FStar.Tactics.V2.Derived.apply_lemma",
"Prims.bool",
"FStar.Reflection.V2.Arith.Neg"
] | [
"recursion"
] | false | true | false | false | false | let rec canon_point e =
| let skip () : Tac expr =
trefl ();
e
in
match e with
| Plus (Lit a) (Lit b) ->
norm [primops];
trefl ();
Lit (a + b)
| Mult (Lit a) (Lit b) ->
norm [delta; primops];
trefl ();
Lit (a * b)
| Neg e ->
step_lemma (`neg_minus_one);
canon_point (Mult (Lit (- 1)) e)
| Mult a (Plus b c) ->
step_lemma (`distr);
step_lemma (`cong_plus);
let l = canon_point (Mult a b) in
let r = canon_point (Mult a c) in
canon_point (Plus l r)
| Mult (Plus a b) c ->
step_lemma (`distl);
step_lemma (`cong_plus);
let l = canon_point (Mult a c) in
let r = canon_point (Mult b c) in
canon_point (Plus l r)
| Mult a (Mult b c) ->
step_lemma (`ass_mult_l);
step_lemma (`cong_mult);
let l = canon_point (Mult a b) in
let r = canon_point c in
canon_point (Mult l r)
| Plus a (Plus b c) ->
step_lemma (`ass_plus_l);
step_lemma (`cong_plus);
let l = canon_point (Plus a b) in
let r = canon_point c in
canon_point (Plus l r)
| Plus (Plus a b) c ->
if O.gt (compare_expr b c)
then
(step_lemma (`sw_plus);
apply_lemma (`cong_plus);
let l = canon_point (Plus a c) in
trefl ();
Plus l b)
else skip ()
| Mult (Mult a b) c ->
if O.gt (compare_expr b c)
then
(step_lemma (`sw_mult);
apply_lemma (`cong_mult);
let l = canon_point (Mult a c) in
trefl ();
Mult l b)
else skip ()
| Plus a (Lit 0) ->
apply_lemma (`x_plus_zero);
a
| Plus (Lit 0) b ->
apply_lemma (`zero_plus_x);
b
| Plus a b ->
if O.gt (compare_expr a b)
then
(apply_lemma (`comm_plus);
Plus b a)
else skip ()
| Mult (Lit 0) _ ->
apply_lemma (`zero_mult_x);
Lit 0
| Mult _ (Lit 0) ->
apply_lemma (`x_mult_zero);
Lit 0
| Mult (Lit 1) r ->
apply_lemma (`one_mult_x);
r
| Mult l (Lit 1) ->
apply_lemma (`x_mult_one);
l
| Mult a b ->
if O.gt (compare_expr a b)
then
(apply_lemma (`comm_mult);
Mult b a)
else skip ()
| Minus a b ->
step_lemma (`minus_is_plus);
step_lemma (`cong_plus);
trefl ();
let negb =
match b with
| Lit n -> Lit (- n)
| _ -> Neg b
in
let r = canon_point negb in
canon_point (Plus a r)
| _ -> skip () | false |
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.lemma_blocki_aux2 | val lemma_blocki_aux2 (a: blake_alg) (s1 s2: bytes) (nb1 nb2: nat) (i: nat{i < nb2})
: Lemma (requires S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a)
(ensures
Spec.Blake2.get_blocki (to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1)) | val lemma_blocki_aux2 (a: blake_alg) (s1 s2: bytes) (nb1 nb2: nat) (i: nat{i < nb2})
: Lemma (requires S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a)
(ensures
Spec.Blake2.get_blocki (to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1)) | let lemma_blocki_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (i:nat{i < nb2})
: Lemma
(requires
S.length s1 == nb1 * block_length a /\
S.length s2 == nb2 * block_length a)
(ensures Spec.Blake2.get_blocki (to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1))
= let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
calc (==) {
Spec.Blake2.get_blocki a' s (i + nb1);
(==) { }
S.slice s ((i + nb1) * block_length a) ((i + nb1 + 1) * block_length a);
(==) { }
S.slice s (i * block_length a + nb1 * block_length a) ((i + 1) * block_length a + nb1 * block_length a);
(==) { }
S.slice s (i * block_length a + S.length s1) ((i + 1) * block_length a + S.length s1);
(==) { S.slice_slice s (S.length s1) (S.length s) (i * block_length a) ((i+1) * block_length a) }
S.slice (S.slice s (S.length s1) (S.length s)) (i * block_length a) ((i+1) * block_length a);
(==) { S.append_slices s1 s2; assert (s2 `S.equal` S.slice s (S.length s1) (S.length s)) }
S.slice s2 (i * block_length a) ((i+1) * block_length a);
(==) { }
Spec.Blake2.get_blocki a' s2 i;
} | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 106,
"start_col": 0,
"start_line": 83
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50"
let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h
let update_multi_zero_blake a prevlen h =
Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h
#pop-options
#push-options "--fuel 1"
let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input) == (update a h input))
=
let h1 = update_multi a h () input in
assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input);
if S.length input = 0 then
begin
assert(h1 == h)
end
else
begin
let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in
let h2 = update a h block in
assert(rem `Seq.equal` Seq.empty);
assert(block `Seq.equal` input);
let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in
assert(h1 == h3)
end
#pop-options
let update_multi_associative (a: hash_alg{not (is_blake a)})
(h: words_state a)
(input1: bytes)
(input2: bytes):
Lemma
(requires
S.length input1 % block_length a == 0 /\
S.length input2 % block_length a == 0)
(ensures (
let input = S.append input1 input2 in
S.length input % block_length a == 0 /\
update_multi a (update_multi a h () input1) () input2 == update_multi a h () input))
= match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a /8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
let input = input1 `S.append` input2 in
assert (input1 `S.equal` S.slice input 0 (S.length input1));
assert (input2 `S.equal` S.slice input (S.length input1) (S.length input));
Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h
let lemma_blocki_aux1 (a:blake_alg) (s1 s2:bytes) (i:nat{i < S.length s1 / block_length a})
: Lemma (Spec.Blake2.get_blocki (to_blake_alg a) s1 i == Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
= assert (Spec.Blake2.get_blocki (to_blake_alg a) s1 i `S.equal` Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
#push-options "--fuel 0 --ifuel 0 --z3rlimit 300"
open FStar.Mul | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.blake_alg ->
s1: Spec.Hash.Definitions.bytes ->
s2: Spec.Hash.Definitions.bytes ->
nb1: Prims.nat ->
nb2: Prims.nat ->
i: Prims.nat{i < nb2}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length s1 == nb1 * Spec.Hash.Definitions.block_length a /\
FStar.Seq.Base.length s2 == nb2 * Spec.Hash.Definitions.block_length a)
(ensures
Spec.Blake2.get_blocki (Spec.Hash.Definitions.to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (Spec.Hash.Definitions.to_blake_alg a)
(FStar.Seq.Base.append s1 s2)
(i + nb1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.blake_alg",
"Spec.Hash.Definitions.bytes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Calc.calc_finish",
"Spec.Blake2.Definitions.block_s",
"Prims.eq2",
"Spec.Blake2.get_blocki",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Seq.Base.slice",
"Lib.IntTypes.uint8",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.block_length",
"FStar.Seq.Base.length",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Seq.Properties.slice_slice",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.append_slices",
"Spec.Blake2.Definitions.alg",
"Spec.Hash.Definitions.to_blake_alg",
"FStar.Seq.Base.seq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.append",
"Prims.l_and",
"Prims.int",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_blocki_aux2 (a: blake_alg) (s1 s2: bytes) (nb1 nb2: nat) (i: nat{i < nb2})
: Lemma (requires S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a)
(ensures
Spec.Blake2.get_blocki (to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1)) =
| let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
calc ( == ) {
Spec.Blake2.get_blocki a' s (i + nb1);
( == ) { () }
S.slice s ((i + nb1) * block_length a) ((i + nb1 + 1) * block_length a);
( == ) { () }
S.slice s
(i * block_length a + nb1 * block_length a)
((i + 1) * block_length a + nb1 * block_length a);
( == ) { () }
S.slice s (i * block_length a + S.length s1) ((i + 1) * block_length a + S.length s1);
( == ) { S.slice_slice s
(S.length s1)
(S.length s)
(i * block_length a)
((i + 1) * block_length a) }
S.slice (S.slice s (S.length s1) (S.length s)) (i * block_length a) ((i + 1) * block_length a);
( == ) { (S.append_slices s1 s2;
assert (s2 `S.equal` (S.slice s (S.length s1) (S.length s)))) }
S.slice s2 (i * block_length a) ((i + 1) * block_length a);
( == ) { () }
Spec.Blake2.get_blocki a' s2 i;
} | false |
TwoLockQueue.fst | TwoLockQueue.full | val full : Steel.FractionalPermission.perm | let full = full_perm | {
"file_name": "share/steel/examples/steel/TwoLockQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 30,
"start_col": 0,
"start_line": 30
} | module TwoLockQueue
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.FractionalPermission
open Steel.Reference
open Steel.SpinLock
module L = FStar.List.Tot
module U = Steel.Utils
module Q = Queue
/// This module provides an implementation of Michael and Scott's two lock queue, using the
/// abstract interface for queues provided in Queue.fsti.
/// This implementation allows an enqueue and a dequeue operation to safely operate in parallel.
/// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation,
/// ensuring that at most one enqueue (resp. dequeue) is happening at any time
/// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue
#push-options "--ide_id_info_off"
/// Adding the definition of the vprop equivalence to the context, for proof purposes
let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) =
Classical.forall_intro_2 reveal_equiv
(* Some wrappers to reduce clutter in the code *) | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Queue.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "TwoLockQueue.fst"
} | [
{
"abbrev": true,
"full_module": "Queue",
"short_module": "Q"
},
{
"abbrev": true,
"full_module": "Steel.Utils",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Steel.FractionalPermission.perm | Prims.Tot | [
"total"
] | [] | [
"Steel.FractionalPermission.full_perm"
] | [] | false | false | false | true | false | let full =
| full_perm | false |
|
Spec.Hash.Lemmas.fst | Spec.Hash.Lemmas.lemma_update_aux2 | val lemma_update_aux2
(a: blake_alg)
(s1 s2: bytes)
(nb1 nb2 prevlen1 prevlen2: nat)
(i: nat{i < nb2})
(acc: words_state a)
: Lemma
(requires
S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a /\
prevlen1 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length s1 /\
(S.length (S.append s1 s2) + prevlen1) `less_than_max_input_length` a)
(ensures
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen1 (s1 `S.append` s2) (i + nb1) acc ==
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen2 s2 i acc) | val lemma_update_aux2
(a: blake_alg)
(s1 s2: bytes)
(nb1 nb2 prevlen1 prevlen2: nat)
(i: nat{i < nb2})
(acc: words_state a)
: Lemma
(requires
S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a /\
prevlen1 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length s1 /\
(S.length (S.append s1 s2) + prevlen1) `less_than_max_input_length` a)
(ensures
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen1 (s1 `S.append` s2) (i + nb1) acc ==
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen2 s2 i acc) | let lemma_update_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (prevlen1 prevlen2:nat) (i:nat{i < nb2}) (acc:words_state a)
: Lemma
(requires
S.length s1 == nb1 * block_length a /\
S.length s2 == nb2 * block_length a /\
prevlen1 % block_length a == 0 /\
prevlen2 = prevlen1 + S.length s1 /\
(S.length (S.append s1 s2) + prevlen1) `less_than_max_input_length` a)
(ensures
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen1 (s1 `S.append` s2) (i + nb1) acc ==
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen2 s2 i acc)
= let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
let open Spec.Blake2 in
let f1 = blake2_update1 (to_blake_alg a) prevlen1 s in
let f2 = blake2_update1 (to_blake_alg a) prevlen2 s2 in
let totlen1 = prevlen1 + (i + nb1 + 1) * size_block a' in
let totlen2 = prevlen2 + (i + 1) * size_block a' in
// Proving totlen1 == totlen2 for the last calc step below
calc (==) {
totlen2;
(==) { }
prevlen2 + (i + 1) * block_length a;
(==) { }
prevlen1 + S.length s1 + (i + 1) * block_length a;
(==) { }
prevlen1 + nb1 * block_length a + (i + 1) * block_length a;
(==) { Math.Lemmas.distributivity_add_left (i + 1) nb1 (block_length a) }
prevlen1 + (i + 1 + nb1) * block_length a;
(==) { }
totlen1;
};
calc (==) {
f1 (i + nb1) acc;
(==) { }
blake2_update_block a' false totlen1 (get_blocki a' s (i + nb1)) acc;
(==) { lemma_blocki_aux2 a s1 s2 nb1 nb2 i }
blake2_update_block a' false totlen1 (get_blocki a' s2 i) acc;
(==) { }
f2 i acc;
} | {
"file_name": "specs/lemmas/Spec.Hash.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 151,
"start_col": 0,
"start_line": 108
} | module Spec.Hash.Lemmas
module S = FStar.Seq
open Lib.IntTypes
open Spec.Agile.Hash
open Spec.Hash.Definitions
friend Spec.Agile.Hash
(** Lemmas about the behavior of update_multi / update_last *)
#push-options "--fuel 0 --ifuel 1 --z3rlimit 50"
let update_multi_zero a h =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_zero (block_length a) (Spec.Agile.Hash.update a) h
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a / 8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
Lib.Sequence.lemma_repeat_blocks_multi rateInBytes S.empty f h;
let nb = 0 / rateInBytes in
Lib.LoopCombinators.eq_repeati0 nb (Lib.Sequence.repeat_blocks_f rateInBytes S.empty f nb) h
let update_multi_zero_blake a prevlen h =
Lib.LoopCombinators.eq_repeati0 (0 / block_length a) (Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen S.empty) h
#pop-options
#push-options "--fuel 1"
let update_multi_update (a: md_alg) (h: words_state a) (input: bytes_block a): Lemma
(ensures (update_multi a h () input) == (update a h input))
=
let h1 = update_multi a h () input in
assert(h1 == Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h input);
if S.length input = 0 then
begin
assert(h1 == h)
end
else
begin
let block, rem = Lib.UpdateMulti.split_block (block_length a) input 1 in
let h2 = update a h block in
assert(rem `Seq.equal` Seq.empty);
assert(block `Seq.equal` input);
let h3 = Lib.UpdateMulti.mk_update_multi (block_length a) (update a) h2 rem in
assert(h1 == h3)
end
#pop-options
let update_multi_associative (a: hash_alg{not (is_blake a)})
(h: words_state a)
(input1: bytes)
(input2: bytes):
Lemma
(requires
S.length input1 % block_length a == 0 /\
S.length input2 % block_length a == 0)
(ensures (
let input = S.append input1 input2 in
S.length input % block_length a == 0 /\
update_multi a (update_multi a h () input1) () input2 == update_multi a h () input))
= match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 ->
Lib.UpdateMulti.update_multi_associative (block_length a) (Spec.Agile.Hash.update a) h input1 input2
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
let rateInBytes = rate a /8 in
let f = Spec.SHA3.absorb_inner rateInBytes in
let input = input1 `S.append` input2 in
assert (input1 `S.equal` S.slice input 0 (S.length input1));
assert (input2 `S.equal` S.slice input (S.length input1) (S.length input));
Lib.Sequence.Lemmas.repeat_blocks_multi_split (block_length a) (S.length input1) input f h
let lemma_blocki_aux1 (a:blake_alg) (s1 s2:bytes) (i:nat{i < S.length s1 / block_length a})
: Lemma (Spec.Blake2.get_blocki (to_blake_alg a) s1 i == Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
= assert (Spec.Blake2.get_blocki (to_blake_alg a) s1 i `S.equal` Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) i)
#push-options "--fuel 0 --ifuel 0 --z3rlimit 300"
open FStar.Mul
let lemma_blocki_aux2 (a:blake_alg) (s1 s2:bytes) (nb1 nb2:nat) (i:nat{i < nb2})
: Lemma
(requires
S.length s1 == nb1 * block_length a /\
S.length s2 == nb2 * block_length a)
(ensures Spec.Blake2.get_blocki (to_blake_alg a) s2 i ==
Spec.Blake2.get_blocki (to_blake_alg a) (S.append s1 s2) (i + nb1))
= let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
calc (==) {
Spec.Blake2.get_blocki a' s (i + nb1);
(==) { }
S.slice s ((i + nb1) * block_length a) ((i + nb1 + 1) * block_length a);
(==) { }
S.slice s (i * block_length a + nb1 * block_length a) ((i + 1) * block_length a + nb1 * block_length a);
(==) { }
S.slice s (i * block_length a + S.length s1) ((i + 1) * block_length a + S.length s1);
(==) { S.slice_slice s (S.length s1) (S.length s) (i * block_length a) ((i+1) * block_length a) }
S.slice (S.slice s (S.length s1) (S.length s)) (i * block_length a) ((i+1) * block_length a);
(==) { S.append_slices s1 s2; assert (s2 `S.equal` S.slice s (S.length s1) (S.length s)) }
S.slice s2 (i * block_length a) ((i+1) * block_length a);
(==) { }
Spec.Blake2.get_blocki a' s2 i;
} | {
"checked_file": "/",
"dependencies": [
"Spec.SHA3.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.Hash.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.blake_alg ->
s1: Spec.Hash.Definitions.bytes ->
s2: Spec.Hash.Definitions.bytes ->
nb1: Prims.nat ->
nb2: Prims.nat ->
prevlen1: Prims.nat ->
prevlen2: Prims.nat ->
i: Prims.nat{i < nb2} ->
acc: Spec.Hash.Definitions.words_state a
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length s1 == nb1 * Spec.Hash.Definitions.block_length a /\
FStar.Seq.Base.length s2 == nb2 * Spec.Hash.Definitions.block_length a /\
prevlen1 % Spec.Hash.Definitions.block_length a == 0 /\
prevlen2 = prevlen1 + FStar.Seq.Base.length s1 /\
Spec.Hash.Definitions.less_than_max_input_length (FStar.Seq.Base.length (FStar.Seq.Base.append
s1
s2) +
prevlen1)
a)
(ensures
Spec.Blake2.blake2_update1 (Spec.Hash.Definitions.to_blake_alg a)
prevlen1
(FStar.Seq.Base.append s1 s2)
(i + nb1)
acc ==
Spec.Blake2.blake2_update1 (Spec.Hash.Definitions.to_blake_alg a) prevlen2 s2 i acc) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.blake_alg",
"Spec.Hash.Definitions.bytes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Spec.Hash.Definitions.words_state",
"FStar.Calc.calc_finish",
"Spec.Blake2.Definitions.state",
"Spec.Hash.Definitions.to_blake_alg",
"Prims.eq2",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Spec.Blake2.blake2_update_block",
"Spec.Blake2.get_blocki",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Spec.Hash.Lemmas.lemma_blocki_aux2",
"Prims.int",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.block_length",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint8",
"FStar.Math.Lemmas.distributivity_add_left",
"Spec.Blake2.Definitions.size_block",
"Prims.l_and",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"Spec.Blake2.Definitions.max_limb",
"Lib.Sequence.lseq",
"Spec.Blake2.Definitions.wt",
"Spec.Blake2.blake2_update1",
"Spec.Blake2.Definitions.alg",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"Prims.op_Modulus",
"Prims.op_Equality",
"Spec.Hash.Definitions.less_than_max_input_length",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_update_aux2
(a: blake_alg)
(s1 s2: bytes)
(nb1 nb2 prevlen1 prevlen2: nat)
(i: nat{i < nb2})
(acc: words_state a)
: Lemma
(requires
S.length s1 == nb1 * block_length a /\ S.length s2 == nb2 * block_length a /\
prevlen1 % block_length a == 0 /\ prevlen2 = prevlen1 + S.length s1 /\
(S.length (S.append s1 s2) + prevlen1) `less_than_max_input_length` a)
(ensures
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen1 (s1 `S.append` s2) (i + nb1) acc ==
Spec.Blake2.blake2_update1 (to_blake_alg a) prevlen2 s2 i acc) =
| let s = s1 `S.append` s2 in
let a' = to_blake_alg a in
let open Spec.Blake2 in
let f1 = blake2_update1 (to_blake_alg a) prevlen1 s in
let f2 = blake2_update1 (to_blake_alg a) prevlen2 s2 in
let totlen1 = prevlen1 + (i + nb1 + 1) * size_block a' in
let totlen2 = prevlen2 + (i + 1) * size_block a' in
calc ( == ) {
totlen2;
( == ) { () }
prevlen2 + (i + 1) * block_length a;
( == ) { () }
prevlen1 + S.length s1 + (i + 1) * block_length a;
( == ) { () }
prevlen1 + nb1 * block_length a + (i + 1) * block_length a;
( == ) { Math.Lemmas.distributivity_add_left (i + 1) nb1 (block_length a) }
prevlen1 + (i + 1 + nb1) * block_length a;
( == ) { () }
totlen1;
};
calc ( == ) {
f1 (i + nb1) acc;
( == ) { () }
blake2_update_block a' false totlen1 (get_blocki a' s (i + nb1)) acc;
( == ) { lemma_blocki_aux2 a s1 s2 nb1 nb2 i }
blake2_update_block a' false totlen1 (get_blocki a' s2 i) acc;
( == ) { () }
f2 i acc;
} | false |
FStar.Tactics.Canon.fst | FStar.Tactics.Canon.canon_point_entry | val canon_point_entry: Prims.unit -> Tac unit | val canon_point_entry: Prims.unit -> Tac unit | let canon_point_entry () : Tac unit =
norm [primops];
let g = cur_goal () in
match term_as_formula g with
| Comp (Eq _) l r ->
begin match run_tm (is_arith_expr l) with
| Inr e -> (let _e = canon_point e in ())
| Inl _ -> trefl ()
end
| _ ->
fail ("impossible: " ^ term_to_string g) | {
"file_name": "ulib/FStar.Tactics.Canon.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 277,
"start_col": 0,
"start_line": 267
} | (*
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 FStar.Tactics.Canon
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.Reflection.V2.Arith
open FStar.Mul
module O = FStar.Order
private
val distr : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y + z) == x * y + x * z)
private
let distr #x #y #z = ()
private
val distl : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) * z == x * z + y * z)
private
let distl #x #y #z = ()
private
val ass_plus_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x + (y + z) == (x + y) + z)
private
let ass_plus_l #x #y #z = ()
private
val ass_mult_l : (#x : int) -> (#y : int) -> (#z : int) -> Lemma (x * (y * z) == (x * y) * z)
private
let ass_mult_l #x #y #z = ()
private
val comm_plus : (#x : int) -> (#y : int) -> Lemma (x + y == y + x)
private
let comm_plus #x #y = ()
private
val sw_plus : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x + y) + z == (x + z) + y)
private
let sw_plus #x #y #z = ()
private
val sw_mult : (#x : int) -> (#y : int) -> (#z : int) -> Lemma ((x * y) * z == (x * z) * y)
private
let sw_mult #x #y #z = ()
private
val comm_mult : (#x : int) -> (#y : int) -> Lemma (x * y == y * x)
private
let comm_mult #x #y = ()
private
val trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) ->
squash (x == y) -> squash (y == z) -> Lemma (x == z)
private
let trans #a #x #z #y e1 e2 = ()
private
val cong_plus : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w + x == y + z)
private
let cong_plus #w #x #y #z p q = ()
private
val cong_mult : (#w:int) -> (#x:int) -> (#y:int) -> (#z:int) ->
squash (w == y) -> squash (x == z) ->
Lemma (w * x == y * z)
private
let cong_mult #w #x #y #z p q = ()
private
val neg_minus_one : (#x:int) -> Lemma (-x == (-1) * x)
private
let neg_minus_one #x = ()
private
val x_plus_zero : (#x:int) -> Lemma (x + 0 == x)
private
let x_plus_zero #x = ()
private
val zero_plus_x : (#x:int) -> Lemma (0 + x == x)
private
let zero_plus_x #x = ()
private
val x_mult_zero : (#x:int) -> Lemma (x * 0 == 0)
private
let x_mult_zero #x = ()
private
val zero_mult_x : (#x:int) -> Lemma (0 * x == 0)
private
let zero_mult_x #x = ()
private
val x_mult_one : (#x:int) -> Lemma (x * 1 == x)
private
let x_mult_one #x = ()
private
val one_mult_x : (#x:int) -> Lemma (1 * x == x)
private
let one_mult_x #x = ()
private
val minus_is_plus : (#x : int) -> (#y : int) -> Lemma (x - y == x + (-y))
private
let minus_is_plus #x #y = ()
private
let step (t : unit -> Tac unit) : Tac unit =
apply_lemma (`trans);
t ()
private
let step_lemma (lem : term) : Tac unit =
step (fun () -> apply_lemma lem)
private val canon_point : expr -> Tac expr
private let rec canon_point e =
let skip () : Tac expr =
trefl (); e
in
match e with
// Evaluate constants
| Plus (Lit a) (Lit b) ->
norm [primops];
trefl ();
Lit (a + b)
| Mult (Lit a) (Lit b) ->
norm [delta; primops]; // Need delta to turn op_Star into op_Multiply, as there's no primop for it
trefl ();
Lit (a * b)
// Forget about negations
| Neg e ->
step_lemma (`neg_minus_one);
canon_point (Mult (Lit (-1)) e)
// Distribute
| Mult a (Plus b c) ->
step_lemma (`distr);
step_lemma (`cong_plus);
let l = canon_point (Mult a b) in
let r = canon_point (Mult a c) in
canon_point (Plus l r)
| Mult (Plus a b) c ->
step_lemma (`distl);
step_lemma (`cong_plus);
let l = canon_point (Mult a c) in
let r = canon_point (Mult b c) in
canon_point (Plus l r)
// Associate to the left
| Mult a (Mult b c) ->
step_lemma (`ass_mult_l);
step_lemma (`cong_mult);
let l = canon_point (Mult a b) in
let r = canon_point c in
canon_point (Mult l r)
| Plus a (Plus b c) ->
step_lemma (`ass_plus_l);
step_lemma (`cong_plus);
let l = canon_point (Plus a b) in
let r = canon_point c in
canon_point (Plus l r)
| Plus (Plus a b) c ->
if O.gt (compare_expr b c)
then begin
step_lemma (`sw_plus);
apply_lemma (`cong_plus);
let l = canon_point (Plus a c) in
trefl() ;
Plus l b
end
else skip ()
| Mult (Mult a b) c ->
if O.gt (compare_expr b c)
then begin
step_lemma (`sw_mult);
apply_lemma (`cong_mult);
let l = canon_point (Mult a c) in
trefl ();
Mult l b
end
else skip ()
| Plus a (Lit 0) ->
apply_lemma (`x_plus_zero);
a
| Plus (Lit 0) b ->
apply_lemma (`zero_plus_x);
b
| Plus a b ->
if O.gt (compare_expr a b)
then (apply_lemma (`comm_plus); Plus b a)
else skip ()
| Mult (Lit 0) _ ->
apply_lemma (`zero_mult_x);
Lit 0
| Mult _ (Lit 0) ->
apply_lemma (`x_mult_zero);
Lit 0
| Mult (Lit 1) r ->
apply_lemma (`one_mult_x);
r
| Mult l (Lit 1) ->
apply_lemma (`x_mult_one);
l
| Mult a b ->
if O.gt (compare_expr a b)
then (apply_lemma (`comm_mult); Mult b a)
else skip ()
// Forget about subtraction
| Minus a b ->
step_lemma (`minus_is_plus);
step_lemma (`cong_plus);
trefl ();
let negb = match b with | Lit n -> Lit (-n) | _ -> Neg b in
// ^ We need to take care wrt literals, since an application (- N)
// will get reduced to the literal -N and then neg_minus_one will not
// apply.
let r = canon_point negb in
canon_point (Plus a r)
| _ ->
skip ()
// On canon_point_entry, we interpret the LHS of the goal as an
// arithmetic expression, of which we keep track in canon_point so we
// avoid reinterpreting the goal, which gives a good speedup.
//
// However, we are repeating work between canon_point_entry calls, since
// in (L + R), we are called once for L, once for R, and once for the
// sum which traverses both (their canonized forms, actually).
//
// The proper way to solve this is have some state-passing in pointwise,
// maybe having the inner tactic be of type (list a -> tactic a), where | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.Arith.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Canon.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Order",
"short_module": "O"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Arith",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.NamedView.term",
"FStar.Reflection.V2.Arith.expr",
"FStar.Tactics.Canon.canon_point",
"Prims.string",
"FStar.Tactics.V2.Derived.trefl",
"FStar.Pervasives.either",
"FStar.Reflection.V2.Arith.run_tm",
"FStar.Reflection.V2.Arith.is_arith_expr",
"FStar.Reflection.V2.Formula.formula",
"FStar.Tactics.V2.Derived.fail",
"Prims.op_Hat",
"FStar.Stubs.Tactics.V2.Builtins.term_to_string",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Tactics.V2.Derived.cur_goal",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.primops",
"Prims.Nil"
] | [] | false | true | false | false | false | let canon_point_entry () : Tac unit =
| norm [primops];
let g = cur_goal () in
match term_as_formula g with
| Comp (Eq _) l r ->
(match run_tm (is_arith_expr l) with
| Inr e ->
(let _e = canon_point e in
())
| Inl _ -> trefl ())
| _ -> fail ("impossible: " ^ term_to_string g) | false |
TwoLockQueue.fst | TwoLockQueue.half | val half : Steel.FractionalPermission.perm | let half = half_perm full | {
"file_name": "share/steel/examples/steel/TwoLockQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 25,
"end_line": 32,
"start_col": 0,
"start_line": 32
} | module TwoLockQueue
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.FractionalPermission
open Steel.Reference
open Steel.SpinLock
module L = FStar.List.Tot
module U = Steel.Utils
module Q = Queue
/// This module provides an implementation of Michael and Scott's two lock queue, using the
/// abstract interface for queues provided in Queue.fsti.
/// This implementation allows an enqueue and a dequeue operation to safely operate in parallel.
/// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation,
/// ensuring that at most one enqueue (resp. dequeue) is happening at any time
/// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue
#push-options "--ide_id_info_off"
/// Adding the definition of the vprop equivalence to the context, for proof purposes
let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) =
Classical.forall_intro_2 reveal_equiv
(* Some wrappers to reduce clutter in the code *)
[@@__reduce__]
let full = full_perm | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Queue.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "TwoLockQueue.fst"
} | [
{
"abbrev": true,
"full_module": "Queue",
"short_module": "Q"
},
{
"abbrev": true,
"full_module": "Steel.Utils",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Steel.FractionalPermission.perm | Prims.Tot | [
"total"
] | [] | [
"Steel.FractionalPermission.half_perm",
"TwoLockQueue.full"
] | [] | false | false | false | true | false | let half =
| half_perm full | false |
|
Trees.fst | Trees.kv_tree | val kv_tree : a: Type -> b: Type -> Type | let kv_tree (a: Type) (b: Type) = tree (node_data a b) | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"Trees.tree",
"Trees.node_data"
] | [] | false | false | false | true | true | let kv_tree (a b: Type) =
| tree (node_data a b) | false |
|
TwoLockQueue.fst | TwoLockQueue.snd | val snd : x: (_ * _) -> _ | let snd x = snd x | {
"file_name": "share/steel/examples/steel/TwoLockQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | module TwoLockQueue
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.FractionalPermission
open Steel.Reference
open Steel.SpinLock
module L = FStar.List.Tot
module U = Steel.Utils
module Q = Queue
/// This module provides an implementation of Michael and Scott's two lock queue, using the
/// abstract interface for queues provided in Queue.fsti.
/// This implementation allows an enqueue and a dequeue operation to safely operate in parallel.
/// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation,
/// ensuring that at most one enqueue (resp. dequeue) is happening at any time
/// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue
#push-options "--ide_id_info_off"
/// Adding the definition of the vprop equivalence to the context, for proof purposes
let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) =
Classical.forall_intro_2 reveal_equiv
(* Some wrappers to reduce clutter in the code *)
[@@__reduce__]
let full = full_perm
[@@__reduce__]
let half = half_perm full
(* Wrappers around fst and snd to avoid overnormalization.
TODO: The frame inference tactic should not normalize fst and snd *) | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Queue.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "TwoLockQueue.fst"
} | [
{
"abbrev": true,
"full_module": "Queue",
"short_module": "Q"
},
{
"abbrev": true,
"full_module": "Steel.Utils",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | x: (_ * _) -> _ | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | true | false | let snd x =
| snd x | false |
|
Trees.fst | Trees.key_left | val key_left : compare: Trees.cmp a -> root: a -> key: a -> Prims.bool | let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0 | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 23,
"end_line": 37,
"start_col": 0,
"start_line": 36
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | compare: Trees.cmp a -> root: a -> key: a -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Trees.cmp",
"Prims.op_GreaterThanOrEqual",
"Prims.bool"
] | [] | false | false | false | true | false | let key_left (#a: Type) (compare: cmp a) (root key: a) =
| compare root key >= 0 | false |
|
TwoLockQueue.fst | TwoLockQueue.fst | val fst : x: (_ * _) -> _ | let fst x = fst x | {
"file_name": "share/steel/examples/steel/TwoLockQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 37,
"start_col": 0,
"start_line": 37
} | module TwoLockQueue
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.FractionalPermission
open Steel.Reference
open Steel.SpinLock
module L = FStar.List.Tot
module U = Steel.Utils
module Q = Queue
/// This module provides an implementation of Michael and Scott's two lock queue, using the
/// abstract interface for queues provided in Queue.fsti.
/// This implementation allows an enqueue and a dequeue operation to safely operate in parallel.
/// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation,
/// ensuring that at most one enqueue (resp. dequeue) is happening at any time
/// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue
#push-options "--ide_id_info_off"
/// Adding the definition of the vprop equivalence to the context, for proof purposes
let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) =
Classical.forall_intro_2 reveal_equiv
(* Some wrappers to reduce clutter in the code *)
[@@__reduce__]
let full = full_perm
[@@__reduce__]
let half = half_perm full
(* Wrappers around fst and snd to avoid overnormalization.
TODO: The frame inference tactic should not normalize fst and snd *) | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Queue.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "TwoLockQueue.fst"
} | [
{
"abbrev": true,
"full_module": "Queue",
"short_module": "Q"
},
{
"abbrev": true,
"full_module": "Steel.Utils",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | x: (_ * _) -> _ | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst"
] | [] | false | false | false | true | false | let fst x =
| fst x | false |
|
Trees.fst | Trees.bst | val bst : a: Type -> cmp: Trees.cmp a -> Type | let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x} | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond
let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0
let key_right (#a: Type) (compare : cmp a) (root key: a) =
compare root key <= 0
let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
is_bst compare left && is_bst compare right &&
forall_keys left (key_left compare data) &&
forall_keys right (key_right compare data) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> cmp: Trees.cmp a -> Type | Prims.Tot | [
"total"
] | [] | [
"Trees.cmp",
"Trees.tree",
"Prims.b2t",
"Trees.is_bst"
] | [] | false | false | false | true | true | let bst (a: Type) (cmp: cmp a) =
| x: tree a {is_bst cmp x} | false |
|
Trees.fst | Trees.key_right | val key_right : compare: Trees.cmp a -> root: a -> key: a -> Prims.bool | let key_right (#a: Type) (compare : cmp a) (root key: a) =
compare root key <= 0 | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 23,
"end_line": 40,
"start_col": 0,
"start_line": 39
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond
let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | compare: Trees.cmp a -> root: a -> key: a -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Trees.cmp",
"Prims.op_LessThanOrEqual",
"Prims.bool"
] | [] | false | false | false | true | false | let key_right (#a: Type) (compare: cmp a) (root key: a) =
| compare root key <= 0 | false |
|
TwoLockQueue.fst | TwoLockQueue.lock_inv | val lock_inv : ptr: Steel.Reference.ref (Queue.Def.t a) -> ghost: Steel.Reference.ghost_ref (Queue.Def.t a)
-> Steel.Effect.Common.vprop | let lock_inv #a (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) =
h_exists (fun (v:Q.t a) ->
pts_to ptr full v `star`
ghost_pts_to ghost half v) | {
"file_name": "share/steel/examples/steel/TwoLockQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 81,
"start_col": 0,
"start_line": 78
} | module TwoLockQueue
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.FractionalPermission
open Steel.Reference
open Steel.SpinLock
module L = FStar.List.Tot
module U = Steel.Utils
module Q = Queue
/// This module provides an implementation of Michael and Scott's two lock queue, using the
/// abstract interface for queues provided in Queue.fsti.
/// This implementation allows an enqueue and a dequeue operation to safely operate in parallel.
/// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation,
/// ensuring that at most one enqueue (resp. dequeue) is happening at any time
/// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue
#push-options "--ide_id_info_off"
/// Adding the definition of the vprop equivalence to the context, for proof purposes
let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) =
Classical.forall_intro_2 reveal_equiv
(* Some wrappers to reduce clutter in the code *)
[@@__reduce__]
let full = full_perm
[@@__reduce__]
let half = half_perm full
(* Wrappers around fst and snd to avoid overnormalization.
TODO: The frame inference tactic should not normalize fst and snd *)
let fst x = fst x
let snd x = snd x
(* Some wrappers around Steel functions which are easier to use inside this module *)
let ghost_gather (#a:Type) (#u:_)
(#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1})
(x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r p x0)
(requires fun _ -> True)
(ensures fun _ _ _ -> x0 == x1)
= let _ = ghost_gather_pt #a #u #p0 #p1 r in ()
let rewrite #u (p q:vprop)
: SteelGhost unit u p (fun _ -> q)
(requires fun _ -> p `equiv` q)
(ensures fun _ _ _ -> True)
= rewrite_slprop p q (fun _ -> reveal_equiv p q)
let elim_pure (#p:prop) #u ()
: SteelGhost unit u
(pure p) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> p)
= let _ = Steel.Effect.Atomic.elim_pure p in ()
let open_exists (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit)
: SteelGhostT (Ghost.erased a) opened_invariants
(h_exists p) (fun r -> p (reveal r))
= let v : erased a = witness_exists () in
v
(*** Queue invariant ***)
/// The invariant associated to the lock. Basically a variant of the
/// Owicki-Gries invariant, but applied to queues | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Queue.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "TwoLockQueue.fst"
} | [
{
"abbrev": true,
"full_module": "Queue",
"short_module": "Q"
},
{
"abbrev": true,
"full_module": "Steel.Utils",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | ptr: Steel.Reference.ref (Queue.Def.t a) -> ghost: Steel.Reference.ghost_ref (Queue.Def.t a)
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.ref",
"Queue.Def.t",
"Steel.Reference.ghost_ref",
"Steel.Effect.Atomic.h_exists",
"Steel.Effect.Common.star",
"Steel.Reference.pts_to",
"TwoLockQueue.full",
"Steel.Reference.ghost_pts_to",
"TwoLockQueue.half",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | true | false | let lock_inv #a (ptr: ref (Q.t a)) (ghost: ghost_ref (Q.t a)) =
| h_exists (fun (v: Q.t a) -> (pts_to ptr full v) `star` (ghost_pts_to ghost half v)) | false |
|
Trees.fst | Trees.forall_keys | val forall_keys (#a: Type) (t: tree a) (cond: (a -> bool)) : bool | val forall_keys (#a: Type) (t: tree a) (cond: (a -> bool)) : bool | let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 34,
"start_col": 0,
"start_line": 30
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Trees.tree a -> cond: (_: a -> Prims.bool) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Trees.tree",
"Prims.bool",
"Prims.op_AmpAmp",
"Trees.forall_keys"
] | [
"recursion"
] | false | false | false | true | false | let rec forall_keys (#a: Type) (t: tree a) (cond: (a -> bool)) : bool =
| match t with
| Leaf -> true
| Node data left right -> cond data && forall_keys left cond && forall_keys right cond | false |
Trees.fst | Trees.is_avl | val is_avl (#a: Type) (cmp: cmp a) (x: tree a) : prop | val is_avl (#a: Type) (cmp: cmp a) (x: tree a) : prop | let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop =
is_bst cmp x /\ is_balanced x | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 159,
"start_col": 0,
"start_line": 158
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond
let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0
let key_right (#a: Type) (compare : cmp a) (root key: a) =
compare root key <= 0
let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
is_bst compare left && is_bst compare right &&
forall_keys left (key_left compare data) &&
forall_keys right (key_right compare data)
let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x}
(*** Operations *)
(**** Lookup *)
let rec mem (#a: Type) (r: tree a) (x: a) : prop =
match r with
| Leaf -> False
| Node data left right ->
(data == x) \/ (mem right x) \/ mem left x
let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a =
match x with
| Leaf -> None
| Node data left right ->
let delta = cmp data key in
if delta < 0 then bst_search cmp right key else
if delta > 0 then bst_search cmp left key else
Some data
(**** Height *)
let rec height (#a: Type) (x: tree a) : nat =
match x with
| Leaf -> 0
| Node data left right ->
if height left > height right then (height left) + 1
else (height right) + 1
(**** Append *)
let rec append_left (#a: Type) (x: tree a) (v: a) : tree a =
match x with
| Leaf -> Node v Leaf Leaf
| Node x left right -> Node x (append_left left v) right
let rec append_right (#a: Type) (x: tree a) (v: a) : tree a =
match x with
| Leaf -> Node v Leaf Leaf
| Node x left right -> Node x left (append_right right v)
(**** Insertion *)
(**** BST insertion *)
let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a =
match x with
| Leaf -> Node key Leaf Leaf
| Node data left right ->
let delta = cmp data key in
if delta >= 0 then begin
let new_left = insert_bst cmp left key in
Node data new_left right
end else begin
let new_right = insert_bst cmp right key in
Node data left new_right
end
let rec insert_bst_preserves_forall_keys
(#a: Type)
(cmp:cmp a)
(x: bst a cmp)
(key: a)
(cond: a -> bool)
: Lemma
(requires (forall_keys x cond /\ cond key))
(ensures (forall_keys (insert_bst cmp x key) cond))
=
match x with
| Leaf -> ()
| Node data left right ->
let delta = cmp data key in
if delta >= 0 then
insert_bst_preserves_forall_keys cmp left key cond
else
insert_bst_preserves_forall_keys cmp right key cond
let rec insert_bst_preserves_bst
(#a: Type)
(cmp:cmp a)
(x: bst a cmp)
(key: a)
: Lemma(is_bst cmp (insert_bst cmp x key))
=
match x with
| Leaf -> ()
| Node data left right ->
let delta = cmp data key in
if delta >= 0 then begin
insert_bst_preserves_forall_keys cmp left key (key_left cmp data);
insert_bst_preserves_bst cmp left key
end else begin
insert_bst_preserves_forall_keys cmp right key (key_right cmp data);
insert_bst_preserves_bst cmp right key
end
(**** AVL insertion *)
let rec is_balanced (#a: Type) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
M.abs(height right - height left) <= 1 &&
is_balanced(right) &&
is_balanced(left) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | cmp: Trees.cmp a -> x: Trees.tree a -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Trees.cmp",
"Trees.tree",
"Prims.l_and",
"Prims.b2t",
"Trees.is_bst",
"Trees.is_balanced",
"Prims.prop"
] | [] | false | false | false | true | true | let is_avl (#a: Type) (cmp: cmp a) (x: tree a) : prop =
| is_bst cmp x /\ is_balanced x | false |
Trees.fst | Trees.mem | val mem (#a: Type) (r: tree a) (x: a) : prop | val mem (#a: Type) (r: tree a) (x: a) : prop | let rec mem (#a: Type) (r: tree a) (x: a) : prop =
match r with
| Leaf -> False
| Node data left right ->
(data == x) \/ (mem right x) \/ mem left x | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 60,
"start_col": 0,
"start_line": 56
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond
let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0
let key_right (#a: Type) (compare : cmp a) (root key: a) =
compare root key <= 0
let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
is_bst compare left && is_bst compare right &&
forall_keys left (key_left compare data) &&
forall_keys right (key_right compare data)
let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x}
(*** Operations *)
(**** Lookup *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Trees.tree a -> x: a -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Trees.tree",
"Prims.l_False",
"Prims.l_or",
"Prims.eq2",
"Trees.mem",
"Prims.prop"
] | [
"recursion"
] | false | false | false | true | true | let rec mem (#a: Type) (r: tree a) (x: a) : prop =
| match r with
| Leaf -> False
| Node data left right -> (data == x) \/ (mem right x) \/ mem left x | false |
Trees.fst | Trees.is_bst | val is_bst (#a: Type) (compare: cmp a) (x: tree a) : bool | val is_bst (#a: Type) (compare: cmp a) (x: tree a) : bool | let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
is_bst compare left && is_bst compare right &&
forall_keys left (key_left compare data) &&
forall_keys right (key_right compare data) | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 48,
"start_col": 0,
"start_line": 42
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond
let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0
let key_right (#a: Type) (compare : cmp a) (root key: a) =
compare root key <= 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | compare: Trees.cmp a -> x: Trees.tree a -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Trees.cmp",
"Trees.tree",
"Prims.op_AmpAmp",
"Trees.is_bst",
"Trees.forall_keys",
"Trees.key_left",
"Trees.key_right",
"Prims.bool"
] | [
"recursion"
] | false | false | false | true | false | let rec is_bst (#a: Type) (compare: cmp a) (x: tree a) : bool =
| match x with
| Leaf -> true
| Node data left right ->
is_bst compare left && is_bst compare right && forall_keys left (key_left compare data) &&
forall_keys right (key_right compare data) | false |
Trees.fst | Trees.avl | val avl : a: Type -> cmp: Trees.cmp a -> Type | let avl (a: Type) (cmp:cmp a) = x: tree a {is_avl cmp x} | {
"file_name": "share/steel/examples/steel/Trees.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 161,
"start_col": 0,
"start_line": 161
} | module Trees
module M = FStar.Math.Lib
#set-options "--fuel 1 --ifuel 1 --z3rlimit 20"
(*** Type definitions *)
(**** The tree structure *)
type tree (a: Type) =
| Leaf : tree a
| Node: data: a -> left: tree a -> right: tree a -> tree a
(**** Binary search trees *)
type node_data (a b: Type) = {
key: a;
payload: b;
}
let kv_tree (a: Type) (b: Type) = tree (node_data a b)
type cmp (a: Type) = compare: (a -> a -> int){
squash (forall x. compare x x == 0) /\
squash (forall x y. compare x y > 0 <==> compare y x < 0) /\
squash (forall x y z. compare x y >= 0 /\ compare y z >= 0 ==> compare x z >= 0)
}
let rec forall_keys (#a: Type) (t: tree a) (cond: a -> bool) : bool =
match t with
| Leaf -> true
| Node data left right ->
cond data && forall_keys left cond && forall_keys right cond
let key_left (#a: Type) (compare:cmp a) (root key: a) =
compare root key >= 0
let key_right (#a: Type) (compare : cmp a) (root key: a) =
compare root key <= 0
let rec is_bst (#a: Type) (compare : cmp a) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
is_bst compare left && is_bst compare right &&
forall_keys left (key_left compare data) &&
forall_keys right (key_right compare data)
let bst (a: Type) (cmp:cmp a) = x:tree a {is_bst cmp x}
(*** Operations *)
(**** Lookup *)
let rec mem (#a: Type) (r: tree a) (x: a) : prop =
match r with
| Leaf -> False
| Node data left right ->
(data == x) \/ (mem right x) \/ mem left x
let rec bst_search (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : option a =
match x with
| Leaf -> None
| Node data left right ->
let delta = cmp data key in
if delta < 0 then bst_search cmp right key else
if delta > 0 then bst_search cmp left key else
Some data
(**** Height *)
let rec height (#a: Type) (x: tree a) : nat =
match x with
| Leaf -> 0
| Node data left right ->
if height left > height right then (height left) + 1
else (height right) + 1
(**** Append *)
let rec append_left (#a: Type) (x: tree a) (v: a) : tree a =
match x with
| Leaf -> Node v Leaf Leaf
| Node x left right -> Node x (append_left left v) right
let rec append_right (#a: Type) (x: tree a) (v: a) : tree a =
match x with
| Leaf -> Node v Leaf Leaf
| Node x left right -> Node x left (append_right right v)
(**** Insertion *)
(**** BST insertion *)
let rec insert_bst (#a: Type) (cmp:cmp a) (x: bst a cmp) (key: a) : tree a =
match x with
| Leaf -> Node key Leaf Leaf
| Node data left right ->
let delta = cmp data key in
if delta >= 0 then begin
let new_left = insert_bst cmp left key in
Node data new_left right
end else begin
let new_right = insert_bst cmp right key in
Node data left new_right
end
let rec insert_bst_preserves_forall_keys
(#a: Type)
(cmp:cmp a)
(x: bst a cmp)
(key: a)
(cond: a -> bool)
: Lemma
(requires (forall_keys x cond /\ cond key))
(ensures (forall_keys (insert_bst cmp x key) cond))
=
match x with
| Leaf -> ()
| Node data left right ->
let delta = cmp data key in
if delta >= 0 then
insert_bst_preserves_forall_keys cmp left key cond
else
insert_bst_preserves_forall_keys cmp right key cond
let rec insert_bst_preserves_bst
(#a: Type)
(cmp:cmp a)
(x: bst a cmp)
(key: a)
: Lemma(is_bst cmp (insert_bst cmp x key))
=
match x with
| Leaf -> ()
| Node data left right ->
let delta = cmp data key in
if delta >= 0 then begin
insert_bst_preserves_forall_keys cmp left key (key_left cmp data);
insert_bst_preserves_bst cmp left key
end else begin
insert_bst_preserves_forall_keys cmp right key (key_right cmp data);
insert_bst_preserves_bst cmp right key
end
(**** AVL insertion *)
let rec is_balanced (#a: Type) (x: tree a) : bool =
match x with
| Leaf -> true
| Node data left right ->
M.abs(height right - height left) <= 1 &&
is_balanced(right) &&
is_balanced(left)
let is_avl (#a: Type) (cmp:cmp a) (x: tree a) : prop =
is_bst cmp x /\ is_balanced x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Trees.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Math.Lib",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> cmp: Trees.cmp a -> Type | Prims.Tot | [
"total"
] | [] | [
"Trees.cmp",
"Trees.tree",
"Trees.is_avl"
] | [] | false | false | false | true | true | let avl (a: Type) (cmp: cmp a) =
| x: tree a {is_avl cmp x} | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.