effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Pervasives.Lemma | val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v)) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buffer_r_sep #a len v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (buffer_region_of v))
(loc_buffer v));
B.modifies_buffer_elim v p h0 h1 | val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v))
let buffer_r_sep #a len v p h0 h1 = | false | null | true | assert (loc_includes (loc_all_regions_from false (buffer_region_of v)) (loc_buffer v));
B.modifies_buffer_elim v p h0 h1 | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [
"lemma"
] | [
"FStar.UInt32.t",
"Prims.b2t",
"FStar.Integers.op_Greater",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.UInt32.__uint_to_t",
"LowStar.Buffer.buffer",
"LowStar.Monotonic.Buffer.loc",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.modifies_buffer_elim",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims._assert",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_all_regions_from",
"LowStar.Regional.Instances.buffer_region_of",
"LowStar.Monotonic.Buffer.loc_buffer"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = B.as_seq h v
val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v)) | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v)) | [] | LowStar.Regional.Instances.buffer_r_sep | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
len: FStar.UInt32.t{len > 0ul} ->
v: LowStar.Buffer.buffer a ->
p: LowStar.Monotonic.Buffer.loc ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Regional.Instances.buffer_r_inv len h0 v /\
LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_all_regions_from false
(LowStar.Regional.Instances.buffer_region_of v))
p /\ LowStar.Monotonic.Buffer.modifies p h0 h1)
(ensures
LowStar.Regional.Instances.buffer_r_inv len h1 v /\
LowStar.Regional.Instances.buffer_r_repr len h0 v ==
LowStar.Regional.Instances.buffer_r_repr len h1 v) | {
"end_col": 34,
"end_line": 79,
"start_col": 2,
"start_line": 77
} |
FStar.HyperStack.ST.ST | val vector_r_alloc:
#a:Type0 -> #rst:Type -> rg:regional rst a -> r:HST.erid ->
HST.ST (rvector rg)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (V.loc_vector v) h0 h1 /\
vector_r_alloc_p rg v /\
vector_r_inv rg h1 v /\
vector_region_of rg v = r /\
vector_r_repr rg h1 v == Ghost.reveal (vector_irepr rg))) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vector_r_alloc #a #rst rg r =
let nrid = HST.new_region r in
V.alloc_reserve 1ul (rg_dummy rg) r | val vector_r_alloc:
#a:Type0 -> #rst:Type -> rg:regional rst a -> r:HST.erid ->
HST.ST (rvector rg)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (V.loc_vector v) h0 h1 /\
vector_r_alloc_p rg v /\
vector_r_inv rg h1 v /\
vector_region_of rg v = r /\
vector_r_repr rg h1 v == Ghost.reveal (vector_irepr rg)))
let vector_r_alloc #a #rst rg r = | true | null | false | let nrid = HST.new_region r in
V.alloc_reserve 1ul (rg_dummy rg) r | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [] | [
"LowStar.Regional.regional",
"FStar.HyperStack.ST.erid",
"LowStar.Vector.alloc_reserve",
"FStar.UInt32.__uint_to_t",
"LowStar.Regional.rg_dummy",
"LowStar.Vector.vector",
"FStar.Monotonic.HyperHeap.rid",
"FStar.HyperStack.ST.new_region",
"LowStar.RVector.rvector"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = B.as_seq h v
val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v))
let buffer_r_sep #a len v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (buffer_region_of v))
(loc_buffer v));
B.modifies_buffer_elim v p h0 h1
val buffer_irepr:
#a:Type0 -> ia:a -> len:UInt32.t{len > 0ul} ->
Ghost.erased (buffer_repr a (UInt32.v len))
let buffer_irepr #a ia len =
Ghost.hide (S.create (UInt32.v len) ia)
val buffer_r_alloc_p:
#a:Type0 -> v:B.buffer a -> GTot Type0
let buffer_r_alloc_p #a v =
True
/// This is the key example here that illustrates how to efficiently do
/// closure-conversion by hand: we have at run-time a function that takes
/// ``arg`` (an actual parameter) that contains the closure state. However, if
/// the function only takes ``arg``, it will have a type that is too
/// polymorphic, i.e. it'll have type ``forall arg. arg -> ...``. Therefore, we
/// add ``arg'`` which is an erased, type-only index which, once instantiated,
/// restricts the domain of the function to operate on the sole value being
/// captured.
val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len)))
let buffer_r_alloc #a #_ (ia, len) r =
B.malloc r ia len
val buffer_r_free:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero) { arg == Ghost.reveal arg' } ->
v:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let ia = fst arg in
let len = snd arg in
buffer_r_inv len h0 v))
(ensures (fun h0 _ h1 ->
modifies (loc_all_regions_from false (buffer_region_of v)) h0 h1))
let buffer_r_free #a len v =
B.free v
val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src))
let buffer_copy #a #_ (ia, len) src dst =
B.blit src 0ul dst 0ul len
#set-options "--print_implicits"
val buffer_regional:
#a:Type -> ia:a -> len:nonzero ->
regional (a & nonzero) (B.buffer a)
let buffer_regional #a ia len =
Rgl (ia, len)
(buffer_region_of #a)
B.loc_buffer
(buffer_dummy a)
(buffer_r_inv #a len)
(buffer_r_inv_reg #a len)
(buffer_repr a (UInt32.v len))
(buffer_r_repr #a len)
(buffer_r_sep #a len)
(buffer_irepr #a ia len)
(buffer_r_alloc_p #a)
// This is key: there is no partial application here, meaning this extracts to C.
(buffer_r_alloc #a #(ia, len))
(buffer_r_free #a #(ia, len))
val buffer_copyable:
#a:Type -> ia:a -> len:nonzero ->
copyable #(a & nonzero) (B.buffer a) (buffer_regional ia len)
let buffer_copyable #a ia len =
Cpy (buffer_copy #_ #(ia, len))
/// If `a` is regional, then `vector a` is also regional.
///
/// We keep a pointer at run-time to the parent type-class.
val vector_region_of:
#a:Type0 -> #rst:Type -> rg:regional rst a -> v:rvector rg -> GTot HS.rid
let vector_region_of #a #rst rg v = V.frameOf v
val vector_dummy:
#a:Type0 -> #rst:Type -> rg:Ghost.erased (regional rst a) -> Tot (rvector rg)
let vector_dummy #a #_ _ = V.alloc_empty a
val vector_r_inv:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg -> GTot Type0
let vector_r_inv #a #rst rg h v = RV.rv_inv h v
val vector_r_inv_reg:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg ->
Lemma (requires (vector_r_inv rg h v))
(ensures (HS.live_region h (vector_region_of rg v)))
let vector_r_inv_reg #a #rst rg h v = ()
val vector_repr: #a:Type0 -> #rst:Type -> rg:regional rst a -> Tot Type0
let vector_repr #a #rst rg = S.seq (Rgl?.repr rg)
val vector_r_repr:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg{vector_r_inv rg h v} ->
GTot (vector_repr rg)
let vector_r_repr #a #rst rg h v = RV.as_seq h v
val vector_r_sep:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
v:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (vector_r_inv rg h0 v /\
loc_disjoint
(loc_all_regions_from false (vector_region_of rg v))
p /\
modifies p h0 h1))
(ensures (vector_r_inv rg h1 v /\
vector_r_repr rg h0 v == vector_r_repr rg h1 v))
let vector_r_sep #a #rst rg v p h0 h1 =
RV.rv_inv_preserved v p h0 h1;
RV.as_seq_preserved v p h0 h1
val vector_irepr:
#a:Type0 -> #rst:Type -> rg:regional rst a -> Ghost.erased (vector_repr rg)
let vector_irepr #a #rst rg =
Ghost.hide S.empty
val vector_r_alloc_p:
#a:Type0 -> #rst:Type -> rg:regional rst a -> v:rvector rg -> GTot Type0
let vector_r_alloc_p #a #rst rg v =
V.size_of v = 0ul
val vector_r_alloc:
#a:Type0 -> #rst:Type -> rg:regional rst a -> r:HST.erid ->
HST.ST (rvector rg)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (V.loc_vector v) h0 h1 /\
vector_r_alloc_p rg v /\
vector_r_inv rg h1 v /\
vector_region_of rg v = r /\ | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vector_r_alloc:
#a:Type0 -> #rst:Type -> rg:regional rst a -> r:HST.erid ->
HST.ST (rvector rg)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (V.loc_vector v) h0 h1 /\
vector_r_alloc_p rg v /\
vector_r_inv rg h1 v /\
vector_region_of rg v = r /\
vector_r_repr rg h1 v == Ghost.reveal (vector_irepr rg))) | [] | LowStar.Regional.Instances.vector_r_alloc | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | rg: LowStar.Regional.regional rst a -> r: FStar.HyperStack.ST.erid
-> FStar.HyperStack.ST.ST (LowStar.RVector.rvector rg) | {
"end_col": 37,
"end_line": 251,
"start_col": 33,
"start_line": 249
} |
Prims.Tot | val vector_regional:
#a:Type0 -> #rst:Type -> rg:regional rst a -> regional (regional rst a) (rvector rg) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vector_regional #a #rst rg =
Rgl rg
(vector_region_of #a #rst rg)
V.loc_vector
(vector_dummy #a #rst rg)
(vector_r_inv #a #rst rg)
(vector_r_inv_reg #a #rst rg)
(vector_repr #a rg)
(vector_r_repr #a #rst rg)
(vector_r_sep #a #rst rg)
(vector_irepr #a rg)
(vector_r_alloc_p #a #rst rg)
(vector_r_alloc #a #rst)
(vector_r_free #a #rst #rg) | val vector_regional:
#a:Type0 -> #rst:Type -> rg:regional rst a -> regional (regional rst a) (rvector rg)
let vector_regional #a #rst rg = | false | null | false | Rgl rg
(vector_region_of #a #rst rg)
V.loc_vector
(vector_dummy #a #rst rg)
(vector_r_inv #a #rst rg)
(vector_r_inv_reg #a #rst rg)
(vector_repr #a rg)
(vector_r_repr #a #rst rg)
(vector_r_sep #a #rst rg)
(vector_irepr #a rg)
(vector_r_alloc_p #a #rst rg)
(vector_r_alloc #a #rst)
(vector_r_free #a #rst #rg) | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [
"total"
] | [
"LowStar.Regional.regional",
"LowStar.Regional.Rgl",
"LowStar.RVector.rvector",
"LowStar.Regional.Instances.vector_region_of",
"LowStar.Vector.loc_vector",
"LowStar.Regional.Instances.vector_dummy",
"FStar.Ghost.hide",
"LowStar.Regional.Instances.vector_r_inv",
"LowStar.Regional.Instances.vector_r_inv_reg",
"LowStar.Regional.Instances.vector_repr",
"LowStar.Regional.Instances.vector_r_repr",
"LowStar.Regional.Instances.vector_r_sep",
"LowStar.Regional.Instances.vector_irepr",
"LowStar.Regional.Instances.vector_r_alloc_p",
"LowStar.Regional.Instances.vector_r_alloc",
"LowStar.Regional.Instances.vector_r_free"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = B.as_seq h v
val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v))
let buffer_r_sep #a len v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (buffer_region_of v))
(loc_buffer v));
B.modifies_buffer_elim v p h0 h1
val buffer_irepr:
#a:Type0 -> ia:a -> len:UInt32.t{len > 0ul} ->
Ghost.erased (buffer_repr a (UInt32.v len))
let buffer_irepr #a ia len =
Ghost.hide (S.create (UInt32.v len) ia)
val buffer_r_alloc_p:
#a:Type0 -> v:B.buffer a -> GTot Type0
let buffer_r_alloc_p #a v =
True
/// This is the key example here that illustrates how to efficiently do
/// closure-conversion by hand: we have at run-time a function that takes
/// ``arg`` (an actual parameter) that contains the closure state. However, if
/// the function only takes ``arg``, it will have a type that is too
/// polymorphic, i.e. it'll have type ``forall arg. arg -> ...``. Therefore, we
/// add ``arg'`` which is an erased, type-only index which, once instantiated,
/// restricts the domain of the function to operate on the sole value being
/// captured.
val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len)))
let buffer_r_alloc #a #_ (ia, len) r =
B.malloc r ia len
val buffer_r_free:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero) { arg == Ghost.reveal arg' } ->
v:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let ia = fst arg in
let len = snd arg in
buffer_r_inv len h0 v))
(ensures (fun h0 _ h1 ->
modifies (loc_all_regions_from false (buffer_region_of v)) h0 h1))
let buffer_r_free #a len v =
B.free v
val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src))
let buffer_copy #a #_ (ia, len) src dst =
B.blit src 0ul dst 0ul len
#set-options "--print_implicits"
val buffer_regional:
#a:Type -> ia:a -> len:nonzero ->
regional (a & nonzero) (B.buffer a)
let buffer_regional #a ia len =
Rgl (ia, len)
(buffer_region_of #a)
B.loc_buffer
(buffer_dummy a)
(buffer_r_inv #a len)
(buffer_r_inv_reg #a len)
(buffer_repr a (UInt32.v len))
(buffer_r_repr #a len)
(buffer_r_sep #a len)
(buffer_irepr #a ia len)
(buffer_r_alloc_p #a)
// This is key: there is no partial application here, meaning this extracts to C.
(buffer_r_alloc #a #(ia, len))
(buffer_r_free #a #(ia, len))
val buffer_copyable:
#a:Type -> ia:a -> len:nonzero ->
copyable #(a & nonzero) (B.buffer a) (buffer_regional ia len)
let buffer_copyable #a ia len =
Cpy (buffer_copy #_ #(ia, len))
/// If `a` is regional, then `vector a` is also regional.
///
/// We keep a pointer at run-time to the parent type-class.
val vector_region_of:
#a:Type0 -> #rst:Type -> rg:regional rst a -> v:rvector rg -> GTot HS.rid
let vector_region_of #a #rst rg v = V.frameOf v
val vector_dummy:
#a:Type0 -> #rst:Type -> rg:Ghost.erased (regional rst a) -> Tot (rvector rg)
let vector_dummy #a #_ _ = V.alloc_empty a
val vector_r_inv:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg -> GTot Type0
let vector_r_inv #a #rst rg h v = RV.rv_inv h v
val vector_r_inv_reg:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg ->
Lemma (requires (vector_r_inv rg h v))
(ensures (HS.live_region h (vector_region_of rg v)))
let vector_r_inv_reg #a #rst rg h v = ()
val vector_repr: #a:Type0 -> #rst:Type -> rg:regional rst a -> Tot Type0
let vector_repr #a #rst rg = S.seq (Rgl?.repr rg)
val vector_r_repr:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg{vector_r_inv rg h v} ->
GTot (vector_repr rg)
let vector_r_repr #a #rst rg h v = RV.as_seq h v
val vector_r_sep:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
v:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (vector_r_inv rg h0 v /\
loc_disjoint
(loc_all_regions_from false (vector_region_of rg v))
p /\
modifies p h0 h1))
(ensures (vector_r_inv rg h1 v /\
vector_r_repr rg h0 v == vector_r_repr rg h1 v))
let vector_r_sep #a #rst rg v p h0 h1 =
RV.rv_inv_preserved v p h0 h1;
RV.as_seq_preserved v p h0 h1
val vector_irepr:
#a:Type0 -> #rst:Type -> rg:regional rst a -> Ghost.erased (vector_repr rg)
let vector_irepr #a #rst rg =
Ghost.hide S.empty
val vector_r_alloc_p:
#a:Type0 -> #rst:Type -> rg:regional rst a -> v:rvector rg -> GTot Type0
let vector_r_alloc_p #a #rst rg v =
V.size_of v = 0ul
val vector_r_alloc:
#a:Type0 -> #rst:Type -> rg:regional rst a -> r:HST.erid ->
HST.ST (rvector rg)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (V.loc_vector v) h0 h1 /\
vector_r_alloc_p rg v /\
vector_r_inv rg h1 v /\
vector_region_of rg v = r /\
vector_r_repr rg h1 v == Ghost.reveal (vector_irepr rg)))
let vector_r_alloc #a #rst rg r =
let nrid = HST.new_region r in
V.alloc_reserve 1ul (rg_dummy rg) r
val vector_r_free:
#a:Type0 -> #rst:Type -> #rg:Ghost.erased (regional rst a) -> (s:regional rst a{s == Ghost.reveal rg}) -> v:rvector rg ->
HST.ST unit
(requires (fun h0 -> vector_r_inv rg h0 v))
(ensures (fun h0 _ h1 ->
modifies (loc_all_regions_from false (vector_region_of rg v)) h0 h1))
let vector_r_free #_ #_ _ v =
V.free v
val vector_regional:
#a:Type0 -> #rst:Type -> rg:regional rst a -> regional (regional rst a) (rvector rg) | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vector_regional:
#a:Type0 -> #rst:Type -> rg:regional rst a -> regional (regional rst a) (rvector rg) | [] | LowStar.Regional.Instances.vector_regional | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | rg: LowStar.Regional.regional rst a
-> LowStar.Regional.regional (LowStar.Regional.regional rst a) (LowStar.RVector.rvector rg) | {
"end_col": 33,
"end_line": 277,
"start_col": 2,
"start_line": 265
} |
Prims.GTot | val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len)) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buffer_r_repr #a len h v = B.as_seq h v | val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = | false | null | false | B.as_seq h v | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [
"sometrivial"
] | [
"FStar.UInt32.t",
"Prims.b2t",
"FStar.Integers.op_Greater",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Buffer.buffer",
"LowStar.Regional.Instances.buffer_r_inv",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Buffer.trivial_preorder",
"LowStar.Regional.Instances.buffer_repr",
"FStar.UInt32.v"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} -> | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len)) | [] | LowStar.Regional.Instances.buffer_r_repr | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
len: FStar.UInt32.t{len > 0ul} ->
h: FStar.Monotonic.HyperStack.mem ->
v: LowStar.Buffer.buffer a {LowStar.Regional.Instances.buffer_r_inv len h v}
-> Prims.GTot (LowStar.Regional.Instances.buffer_repr a (FStar.UInt32.v len)) | {
"end_col": 43,
"end_line": 64,
"start_col": 31,
"start_line": 64
} |
FStar.Pervasives.Lemma | val vector_r_sep:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
v:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (vector_r_inv rg h0 v /\
loc_disjoint
(loc_all_regions_from false (vector_region_of rg v))
p /\
modifies p h0 h1))
(ensures (vector_r_inv rg h1 v /\
vector_r_repr rg h0 v == vector_r_repr rg h1 v)) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vector_r_sep #a #rst rg v p h0 h1 =
RV.rv_inv_preserved v p h0 h1;
RV.as_seq_preserved v p h0 h1 | val vector_r_sep:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
v:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (vector_r_inv rg h0 v /\
loc_disjoint
(loc_all_regions_from false (vector_region_of rg v))
p /\
modifies p h0 h1))
(ensures (vector_r_inv rg h1 v /\
vector_r_repr rg h0 v == vector_r_repr rg h1 v))
let vector_r_sep #a #rst rg v p h0 h1 = | false | null | true | RV.rv_inv_preserved v p h0 h1;
RV.as_seq_preserved v p h0 h1 | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [
"lemma"
] | [
"LowStar.Regional.regional",
"LowStar.RVector.rvector",
"LowStar.Monotonic.Buffer.loc",
"FStar.Monotonic.HyperStack.mem",
"LowStar.RVector.as_seq_preserved",
"Prims.unit",
"LowStar.RVector.rv_inv_preserved"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = B.as_seq h v
val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v))
let buffer_r_sep #a len v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (buffer_region_of v))
(loc_buffer v));
B.modifies_buffer_elim v p h0 h1
val buffer_irepr:
#a:Type0 -> ia:a -> len:UInt32.t{len > 0ul} ->
Ghost.erased (buffer_repr a (UInt32.v len))
let buffer_irepr #a ia len =
Ghost.hide (S.create (UInt32.v len) ia)
val buffer_r_alloc_p:
#a:Type0 -> v:B.buffer a -> GTot Type0
let buffer_r_alloc_p #a v =
True
/// This is the key example here that illustrates how to efficiently do
/// closure-conversion by hand: we have at run-time a function that takes
/// ``arg`` (an actual parameter) that contains the closure state. However, if
/// the function only takes ``arg``, it will have a type that is too
/// polymorphic, i.e. it'll have type ``forall arg. arg -> ...``. Therefore, we
/// add ``arg'`` which is an erased, type-only index which, once instantiated,
/// restricts the domain of the function to operate on the sole value being
/// captured.
val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len)))
let buffer_r_alloc #a #_ (ia, len) r =
B.malloc r ia len
val buffer_r_free:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero) { arg == Ghost.reveal arg' } ->
v:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let ia = fst arg in
let len = snd arg in
buffer_r_inv len h0 v))
(ensures (fun h0 _ h1 ->
modifies (loc_all_regions_from false (buffer_region_of v)) h0 h1))
let buffer_r_free #a len v =
B.free v
val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src))
let buffer_copy #a #_ (ia, len) src dst =
B.blit src 0ul dst 0ul len
#set-options "--print_implicits"
val buffer_regional:
#a:Type -> ia:a -> len:nonzero ->
regional (a & nonzero) (B.buffer a)
let buffer_regional #a ia len =
Rgl (ia, len)
(buffer_region_of #a)
B.loc_buffer
(buffer_dummy a)
(buffer_r_inv #a len)
(buffer_r_inv_reg #a len)
(buffer_repr a (UInt32.v len))
(buffer_r_repr #a len)
(buffer_r_sep #a len)
(buffer_irepr #a ia len)
(buffer_r_alloc_p #a)
// This is key: there is no partial application here, meaning this extracts to C.
(buffer_r_alloc #a #(ia, len))
(buffer_r_free #a #(ia, len))
val buffer_copyable:
#a:Type -> ia:a -> len:nonzero ->
copyable #(a & nonzero) (B.buffer a) (buffer_regional ia len)
let buffer_copyable #a ia len =
Cpy (buffer_copy #_ #(ia, len))
/// If `a` is regional, then `vector a` is also regional.
///
/// We keep a pointer at run-time to the parent type-class.
val vector_region_of:
#a:Type0 -> #rst:Type -> rg:regional rst a -> v:rvector rg -> GTot HS.rid
let vector_region_of #a #rst rg v = V.frameOf v
val vector_dummy:
#a:Type0 -> #rst:Type -> rg:Ghost.erased (regional rst a) -> Tot (rvector rg)
let vector_dummy #a #_ _ = V.alloc_empty a
val vector_r_inv:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg -> GTot Type0
let vector_r_inv #a #rst rg h v = RV.rv_inv h v
val vector_r_inv_reg:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg ->
Lemma (requires (vector_r_inv rg h v))
(ensures (HS.live_region h (vector_region_of rg v)))
let vector_r_inv_reg #a #rst rg h v = ()
val vector_repr: #a:Type0 -> #rst:Type -> rg:regional rst a -> Tot Type0
let vector_repr #a #rst rg = S.seq (Rgl?.repr rg)
val vector_r_repr:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
h:HS.mem -> v:rvector rg{vector_r_inv rg h v} ->
GTot (vector_repr rg)
let vector_r_repr #a #rst rg h v = RV.as_seq h v
val vector_r_sep:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
v:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (vector_r_inv rg h0 v /\
loc_disjoint
(loc_all_regions_from false (vector_region_of rg v))
p /\
modifies p h0 h1))
(ensures (vector_r_inv rg h1 v /\
vector_r_repr rg h0 v == vector_r_repr rg h1 v)) | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vector_r_sep:
#a:Type0 -> #rst:Type -> rg:regional rst a ->
v:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (vector_r_inv rg h0 v /\
loc_disjoint
(loc_all_regions_from false (vector_region_of rg v))
p /\
modifies p h0 h1))
(ensures (vector_r_inv rg h1 v /\
vector_r_repr rg h0 v == vector_r_repr rg h1 v)) | [] | LowStar.Regional.Instances.vector_r_sep | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
rg: LowStar.Regional.regional rst a ->
v: LowStar.RVector.rvector rg ->
p: LowStar.Monotonic.Buffer.loc ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Regional.Instances.vector_r_inv rg h0 v /\
LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_all_regions_from false
(LowStar.Regional.Instances.vector_region_of rg v))
p /\ LowStar.Monotonic.Buffer.modifies p h0 h1)
(ensures
LowStar.Regional.Instances.vector_r_inv rg h1 v /\
LowStar.Regional.Instances.vector_r_repr rg h0 v ==
LowStar.Regional.Instances.vector_r_repr rg h1 v) | {
"end_col": 31,
"end_line": 224,
"start_col": 2,
"start_line": 223
} |
FStar.HyperStack.ST.ST | val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len))) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buffer_r_alloc #a #_ (ia, len) r =
B.malloc r ia len | val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len)))
let buffer_r_alloc #a #_ (ia, len) r = | true | null | false | B.malloc r ia len | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [] | [
"FStar.Ghost.erased",
"FStar.Pervasives.Native.tuple2",
"LowStar.Regional.Instances.nonzero",
"Prims.eq2",
"FStar.Ghost.reveal",
"FStar.HyperStack.ST.erid",
"LowStar.Buffer.malloc",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.Buffer.trivial_preorder",
"Prims.l_and",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Buffer.buffer"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = B.as_seq h v
val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v))
let buffer_r_sep #a len v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (buffer_region_of v))
(loc_buffer v));
B.modifies_buffer_elim v p h0 h1
val buffer_irepr:
#a:Type0 -> ia:a -> len:UInt32.t{len > 0ul} ->
Ghost.erased (buffer_repr a (UInt32.v len))
let buffer_irepr #a ia len =
Ghost.hide (S.create (UInt32.v len) ia)
val buffer_r_alloc_p:
#a:Type0 -> v:B.buffer a -> GTot Type0
let buffer_r_alloc_p #a v =
True
/// This is the key example here that illustrates how to efficiently do
/// closure-conversion by hand: we have at run-time a function that takes
/// ``arg`` (an actual parameter) that contains the closure state. However, if
/// the function only takes ``arg``, it will have a type that is too
/// polymorphic, i.e. it'll have type ``forall arg. arg -> ...``. Therefore, we
/// add ``arg'`` which is an erased, type-only index which, once instantiated,
/// restricts the domain of the function to operate on the sole value being
/// captured.
val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len))) | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len))) | [] | LowStar.Regional.Instances.buffer_r_alloc | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
arg: (a * LowStar.Regional.Instances.nonzero) {arg == FStar.Ghost.reveal arg'} ->
r: FStar.HyperStack.ST.erid
-> FStar.HyperStack.ST.ST (LowStar.Buffer.buffer a) | {
"end_col": 19,
"end_line": 116,
"start_col": 2,
"start_line": 116
} |
FStar.HyperStack.ST.ST | val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src)) | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buffer_copy #a #_ (ia, len) src dst =
B.blit src 0ul dst 0ul len | val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src))
let buffer_copy #a #_ (ia, len) src dst = | true | null | false | B.blit src 0ul dst 0ul len | {
"checked_file": "LowStar.Regional.Instances.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Regional.Instances.fst"
} | [] | [
"FStar.Ghost.erased",
"FStar.Pervasives.Native.tuple2",
"LowStar.Regional.Instances.nonzero",
"Prims.eq2",
"FStar.Ghost.reveal",
"LowStar.Buffer.buffer",
"LowStar.Monotonic.Buffer.blit",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"Prims.unit"
] | [] | (*
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 LowStar.Regional.Instances
open FStar.Integers
open LowStar.Buffer
open LowStar.Regional
open LowStar.RVector
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module S = FStar.Seq
module B = LowStar.Buffer
module V = LowStar.Vector
module RV = LowStar.RVector
/// `LowStar.Buffer` is regional
val buffer_region_of:
#a:Type -> v:B.buffer a -> GTot HS.rid
let buffer_region_of #a v =
B.frameOf v
val buffer_dummy: a:Type -> Tot (B.buffer a)
let buffer_dummy _ = B.null
let nonzero = len:UInt32.t{len > 0ul}
val buffer_r_inv:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a -> GTot Type0
let buffer_r_inv #a len h v =
B.live h v /\ B.freeable v /\
B.len v == len
val buffer_r_inv_reg:
#a:Type -> len:nonzero ->
h:HS.mem -> v:B.buffer a ->
Lemma (requires (buffer_r_inv len h v))
(ensures (HS.live_region h (buffer_region_of v)))
let buffer_r_inv_reg #a len h v = ()
val buffer_repr: a:Type0 -> len:nat{len > 0} -> Type0
let buffer_repr a len = s:S.seq a{S.length s = len}
val buffer_r_repr:
#a:Type -> len:UInt32.t{len > 0ul} ->
h:HS.mem -> v:B.buffer a{buffer_r_inv len h v} ->
GTot (buffer_repr a (UInt32.v len))
let buffer_r_repr #a len h v = B.as_seq h v
val buffer_r_sep:
#a:Type -> len:UInt32.t{len > 0ul} ->
v:B.buffer a -> p:loc -> h0:HS.mem -> h1:HS.mem ->
Lemma (requires (buffer_r_inv len h0 v /\
loc_disjoint
(loc_all_regions_from false
(buffer_region_of v)) p /\
modifies p h0 h1))
(ensures (buffer_r_inv len h1 v /\
buffer_r_repr len h0 v == buffer_r_repr len h1 v))
let buffer_r_sep #a len v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (buffer_region_of v))
(loc_buffer v));
B.modifies_buffer_elim v p h0 h1
val buffer_irepr:
#a:Type0 -> ia:a -> len:UInt32.t{len > 0ul} ->
Ghost.erased (buffer_repr a (UInt32.v len))
let buffer_irepr #a ia len =
Ghost.hide (S.create (UInt32.v len) ia)
val buffer_r_alloc_p:
#a:Type0 -> v:B.buffer a -> GTot Type0
let buffer_r_alloc_p #a v =
True
/// This is the key example here that illustrates how to efficiently do
/// closure-conversion by hand: we have at run-time a function that takes
/// ``arg`` (an actual parameter) that contains the closure state. However, if
/// the function only takes ``arg``, it will have a type that is too
/// polymorphic, i.e. it'll have type ``forall arg. arg -> ...``. Therefore, we
/// add ``arg'`` which is an erased, type-only index which, once instantiated,
/// restricts the domain of the function to operate on the sole value being
/// captured.
val buffer_r_alloc:
#a:Type -> #arg':Ghost.erased (a & nonzero) -> arg:(a & nonzero) { arg == Ghost.reveal arg' } -> r:HST.erid ->
HST.ST (B.buffer a)
(requires (fun h0 -> true))
(ensures (fun h0 v h1 ->
let ia = fst arg in
let len = snd arg in
Set.subset (Map.domain (HS.get_hmap h0))
(Map.domain (HS.get_hmap h1)) /\
modifies loc_none h0 h1 /\
fresh_loc (B.loc_buffer v) h0 h1 /\
buffer_r_alloc_p v /\
buffer_r_inv len h1 v /\
buffer_region_of v = r /\
buffer_r_repr len h1 v == Ghost.reveal (buffer_irepr ia len)))
let buffer_r_alloc #a #_ (ia, len) r =
B.malloc r ia len
val buffer_r_free:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero) { arg == Ghost.reveal arg' } ->
v:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let ia = fst arg in
let len = snd arg in
buffer_r_inv len h0 v))
(ensures (fun h0 _ h1 ->
modifies (loc_all_regions_from false (buffer_region_of v)) h0 h1))
let buffer_r_free #a len v =
B.free v
val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src)) | false | false | LowStar.Regional.Instances.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buffer_copy:
#a:Type ->
#arg':Ghost.erased (a & nonzero) ->
arg:(a & nonzero){ arg == Ghost.reveal arg' } ->
src:B.buffer a -> dst:B.buffer a ->
HST.ST unit
(requires (fun h0 ->
let len = snd arg in
buffer_r_inv len h0 src /\ buffer_r_inv len h0 dst /\
HS.disjoint (buffer_region_of src) (buffer_region_of dst)))
(ensures (fun h0 _ h1 ->
let len = snd arg in
modifies (loc_all_regions_from false (buffer_region_of dst)) h0 h1 /\
buffer_r_inv len h1 dst /\
buffer_r_repr len h1 dst == buffer_r_repr len h0 src)) | [] | LowStar.Regional.Instances.buffer_copy | {
"file_name": "ulib/LowStar.Regional.Instances.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
arg: (a * LowStar.Regional.Instances.nonzero) {arg == FStar.Ghost.reveal arg'} ->
src: LowStar.Buffer.buffer a ->
dst: LowStar.Buffer.buffer a
-> FStar.HyperStack.ST.ST Prims.unit | {
"end_col": 28,
"end_line": 149,
"start_col": 2,
"start_line": 149
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let less_strict_than_max_input_length l a =
match max_input_length a with
| Some max -> l < max
| None -> true | let less_strict_than_max_input_length l a = | false | null | false | match max_input_length a with
| Some max -> l < max
| None -> true | {
"checked_file": "Hacl.HKDF.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"Spec.Agile.HKDF.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.HMAC.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.fsti"
} | [
"total"
] | [
"Prims.int",
"Spec.Hash.Definitions.hash_alg",
"Spec.Hash.Definitions.max_input_length",
"Prims.pos",
"Prims.op_LessThan",
"Prims.bool"
] | [] | module Hacl.HKDF
/// A generic, meta-programmed HKDF module. It provides one concrete
/// instantiation, namely HKDF-SHA2-256 instantiated with the HACL*
/// implementation. In the future, this module may provide more implementations
/// using optimized HACL versions of SHA2-256. For more algorithms, and
/// for an assembly-optimized HKDF version that may call into Vale, see
/// EverCrypt.HKDF.
module B = LowStar.Buffer
open Spec.Hash.Definitions
open Spec.Agile.HKDF
open FStar.HyperStack.ST
open Lib.IntTypes
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
inline_for_extraction noextract | false | true | Hacl.HKDF.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val less_strict_than_max_input_length : l: Prims.int -> a: Spec.Hash.Definitions.hash_alg -> Prims.bool | [] | Hacl.HKDF.less_strict_than_max_input_length | {
"file_name": "code/hkdf/Hacl.HKDF.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | l: Prims.int -> a: Spec.Hash.Definitions.hash_alg -> Prims.bool | {
"end_col": 16,
"end_line": 24,
"start_col": 2,
"start_line": 22
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let extract_st (a:fixed_len_alg) =
prk : B.buffer uint8 ->
salt : B.buffer uint8 ->
saltlen : pub_uint32 ->
ikm : B.buffer uint8 ->
ikmlen : pub_uint32 ->
Stack unit
(requires fun h0 ->
B.live h0 prk /\ B.live h0 salt /\ B.live h0 ikm /\
B.disjoint salt prk /\ B.disjoint ikm prk /\
B.length prk == hash_length a /\
v saltlen == B.length salt /\
v ikmlen == B.length ikm /\
Spec.Agile.HMAC.keysized a (v saltlen) /\
B.length ikm + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
key_and_data_fits a;
B.modifies (B.loc_buffer prk) h0 h1 /\
B.as_seq h1 prk == extract a (B.as_seq h0 salt) (B.as_seq h0 ikm)) | let extract_st (a: fixed_len_alg) = | false | null | false |
prk: B.buffer uint8 ->
salt: B.buffer uint8 ->
saltlen: pub_uint32 ->
ikm: B.buffer uint8 ->
ikmlen: pub_uint32
-> Stack unit
(requires
fun h0 ->
B.live h0 prk /\ B.live h0 salt /\ B.live h0 ikm /\ B.disjoint salt prk /\
B.disjoint ikm prk /\ B.length prk == hash_length a /\ v saltlen == B.length salt /\
v ikmlen == B.length ikm /\ Spec.Agile.HMAC.keysized a (v saltlen) /\
B.length ikm + block_length a < pow2 32)
(ensures
fun h0 _ h1 ->
key_and_data_fits a;
B.modifies (B.loc_buffer prk) h0 h1 /\
B.as_seq h1 prk == extract a (B.as_seq h0 salt) (B.as_seq h0 ikm)) | {
"checked_file": "Hacl.HKDF.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"Spec.Agile.HKDF.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.HMAC.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.fsti"
} | [
"total"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.pub_uint32",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"LowStar.Monotonic.Buffer.disjoint",
"Prims.eq2",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"Spec.Hash.Definitions.hash_length",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Agile.HMAC.keysized",
"Prims.op_LessThan",
"Prims.op_Addition",
"Spec.Hash.Definitions.block_length",
"Prims.pow2",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Spec.Agile.HKDF.extract",
"Hacl.HKDF.key_and_data_fits"
] | [] | module Hacl.HKDF
/// A generic, meta-programmed HKDF module. It provides one concrete
/// instantiation, namely HKDF-SHA2-256 instantiated with the HACL*
/// implementation. In the future, this module may provide more implementations
/// using optimized HACL versions of SHA2-256. For more algorithms, and
/// for an assembly-optimized HKDF version that may call into Vale, see
/// EverCrypt.HKDF.
module B = LowStar.Buffer
open Spec.Hash.Definitions
open Spec.Agile.HKDF
open FStar.HyperStack.ST
open Lib.IntTypes
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_strict_than_max_input_length l a =
match max_input_length a with
| Some max -> l < max
| None -> true
let key_and_data_fits (a:fixed_len_alg) :
Lemma ((block_length a + pow2 32) `less_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125)
let hash_block_length_fits (a:fixed_len_alg) :
Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + 8 * 8 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125)
inline_for_extraction noextract | false | true | Hacl.HKDF.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val extract_st : a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | [] | Hacl.HKDF.extract_st | {
"file_name": "code/hkdf/Hacl.HKDF.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | {
"end_col": 70,
"end_line": 59,
"start_col": 2,
"start_line": 42
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let expand_st (a:fixed_len_alg) =
okm : B.buffer uint8 ->
prk : B.buffer uint8 ->
prklen : pub_uint32 ->
info : B.buffer uint8 ->
infolen : pub_uint32 ->
len : pub_uint32 ->
Stack unit
(requires fun h0 ->
B.live h0 okm /\ B.live h0 prk /\ B.live h0 info /\
B.disjoint okm prk /\
v prklen == B.length prk /\
v infolen == B.length info /\
v len == B.length okm /\
hash_length a <= v prklen /\
Spec.Agile.HMAC.keysized a (v prklen) /\
hash_length a + v infolen + 1 + block_length a < pow2 32 /\
v len <= FStar.Mul.(255 * hash_length a))
(ensures fun h0 _ h1 ->
hash_block_length_fits a;
B.modifies (B.loc_buffer okm) h0 h1 /\
B.as_seq h1 okm == expand a (B.as_seq h0 prk) (B.as_seq h0 info) (v len)) | let expand_st (a: fixed_len_alg) = | false | null | false |
okm: B.buffer uint8 ->
prk: B.buffer uint8 ->
prklen: pub_uint32 ->
info: B.buffer uint8 ->
infolen: pub_uint32 ->
len: pub_uint32
-> Stack unit
(requires
fun h0 ->
B.live h0 okm /\ B.live h0 prk /\ B.live h0 info /\ B.disjoint okm prk /\
v prklen == B.length prk /\ v infolen == B.length info /\ v len == B.length okm /\
hash_length a <= v prklen /\ Spec.Agile.HMAC.keysized a (v prklen) /\
hash_length a + v infolen + 1 + block_length a < pow2 32 /\
v len <= FStar.Mul.(255 * hash_length a))
(ensures
fun h0 _ h1 ->
hash_block_length_fits a;
B.modifies (B.loc_buffer okm) h0 h1 /\
B.as_seq h1 okm == expand a (B.as_seq h0 prk) (B.as_seq h0 info) (v len)) | {
"checked_file": "Hacl.HKDF.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"Spec.Agile.HKDF.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.HMAC.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.fsti"
} | [
"total"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.pub_uint32",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"LowStar.Monotonic.Buffer.disjoint",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"LowStar.Monotonic.Buffer.length",
"Prims.op_LessThanOrEqual",
"Spec.Hash.Definitions.hash_length",
"Spec.Agile.HMAC.keysized",
"Prims.op_LessThan",
"Prims.op_Addition",
"Spec.Hash.Definitions.block_length",
"Prims.pow2",
"FStar.Mul.op_Star",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Spec.Agile.HKDF.expand",
"Hacl.HKDF.hash_block_length_fits"
] | [] | module Hacl.HKDF
/// A generic, meta-programmed HKDF module. It provides one concrete
/// instantiation, namely HKDF-SHA2-256 instantiated with the HACL*
/// implementation. In the future, this module may provide more implementations
/// using optimized HACL versions of SHA2-256. For more algorithms, and
/// for an assembly-optimized HKDF version that may call into Vale, see
/// EverCrypt.HKDF.
module B = LowStar.Buffer
open Spec.Hash.Definitions
open Spec.Agile.HKDF
open FStar.HyperStack.ST
open Lib.IntTypes
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_strict_than_max_input_length l a =
match max_input_length a with
| Some max -> l < max
| None -> true
let key_and_data_fits (a:fixed_len_alg) :
Lemma ((block_length a + pow2 32) `less_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125)
let hash_block_length_fits (a:fixed_len_alg) :
Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + 8 * 8 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125)
inline_for_extraction noextract
let extract_st (a:fixed_len_alg) =
prk : B.buffer uint8 ->
salt : B.buffer uint8 ->
saltlen : pub_uint32 ->
ikm : B.buffer uint8 ->
ikmlen : pub_uint32 ->
Stack unit
(requires fun h0 ->
B.live h0 prk /\ B.live h0 salt /\ B.live h0 ikm /\
B.disjoint salt prk /\ B.disjoint ikm prk /\
B.length prk == hash_length a /\
v saltlen == B.length salt /\
v ikmlen == B.length ikm /\
Spec.Agile.HMAC.keysized a (v saltlen) /\
B.length ikm + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
key_and_data_fits a;
B.modifies (B.loc_buffer prk) h0 h1 /\
B.as_seq h1 prk == extract a (B.as_seq h0 salt) (B.as_seq h0 ikm))
inline_for_extraction noextract | false | true | Hacl.HKDF.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand_st : a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | [] | Hacl.HKDF.expand_st | {
"file_name": "code/hkdf/Hacl.HKDF.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | {
"end_col": 77,
"end_line": 83,
"start_col": 2,
"start_line": 63
} |
|
FStar.Pervasives.Lemma | val hash_block_length_fits (a: fixed_len_alg)
: Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hash_block_length_fits (a:fixed_len_alg) :
Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + 8 * 8 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125) | val hash_block_length_fits (a: fixed_len_alg)
: Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a)
let hash_block_length_fits (a: fixed_len_alg)
: Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a) = | false | null | true | let open FStar.Mul in
assert_norm (8 * 16 + 8 * 8 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125) | {
"checked_file": "Hacl.HKDF.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"Spec.Agile.HKDF.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.HMAC.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.fsti"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.unit",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Hacl.HKDF.less_strict_than_max_input_length",
"Spec.Hash.Definitions.hash_length",
"Spec.Hash.Definitions.block_length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Hacl.HKDF
/// A generic, meta-programmed HKDF module. It provides one concrete
/// instantiation, namely HKDF-SHA2-256 instantiated with the HACL*
/// implementation. In the future, this module may provide more implementations
/// using optimized HACL versions of SHA2-256. For more algorithms, and
/// for an assembly-optimized HKDF version that may call into Vale, see
/// EverCrypt.HKDF.
module B = LowStar.Buffer
open Spec.Hash.Definitions
open Spec.Agile.HKDF
open FStar.HyperStack.ST
open Lib.IntTypes
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_strict_than_max_input_length l a =
match max_input_length a with
| Some max -> l < max
| None -> true
let key_and_data_fits (a:fixed_len_alg) :
Lemma ((block_length a + pow2 32) `less_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125)
let hash_block_length_fits (a:fixed_len_alg) :
Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a) | false | false | Hacl.HKDF.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hash_block_length_fits (a: fixed_len_alg)
: Lemma ((hash_length a + pow2 32 + block_length a) `less_strict_than_max_input_length` a) | [] | Hacl.HKDF.hash_block_length_fits | {
"file_name": "code/hkdf/Hacl.HKDF.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.fixed_len_alg
-> FStar.Pervasives.Lemma
(ensures
Hacl.HKDF.less_strict_than_max_input_length (Spec.Hash.Definitions.hash_length a +
Prims.pow2 32 +
Spec.Hash.Definitions.block_length a)
a) | {
"end_col": 34,
"end_line": 38,
"start_col": 2,
"start_line": 36
} |
FStar.Pervasives.Lemma | val key_and_data_fits (a: fixed_len_alg)
: Lemma ((block_length a + pow2 32) `less_than_max_input_length` a) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let key_and_data_fits (a:fixed_len_alg) :
Lemma ((block_length a + pow2 32) `less_than_max_input_length` a)
=
let open FStar.Mul in
assert_norm (8 * 16 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125) | val key_and_data_fits (a: fixed_len_alg)
: Lemma ((block_length a + pow2 32) `less_than_max_input_length` a)
let key_and_data_fits (a: fixed_len_alg)
: Lemma ((block_length a + pow2 32) `less_than_max_input_length` a) = | false | null | true | let open FStar.Mul in
assert_norm (8 * 16 + pow2 32 < pow2 61);
assert_norm (pow2 61 < pow2 125) | {
"checked_file": "Hacl.HKDF.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"Spec.Agile.HKDF.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.HMAC.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.fsti"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.unit",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Spec.Hash.Definitions.less_than_max_input_length",
"Spec.Hash.Definitions.block_length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Hacl.HKDF
/// A generic, meta-programmed HKDF module. It provides one concrete
/// instantiation, namely HKDF-SHA2-256 instantiated with the HACL*
/// implementation. In the future, this module may provide more implementations
/// using optimized HACL versions of SHA2-256. For more algorithms, and
/// for an assembly-optimized HKDF version that may call into Vale, see
/// EverCrypt.HKDF.
module B = LowStar.Buffer
open Spec.Hash.Definitions
open Spec.Agile.HKDF
open FStar.HyperStack.ST
open Lib.IntTypes
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_strict_than_max_input_length l a =
match max_input_length a with
| Some max -> l < max
| None -> true
let key_and_data_fits (a:fixed_len_alg) :
Lemma ((block_length a + pow2 32) `less_than_max_input_length` a) | false | false | Hacl.HKDF.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_and_data_fits (a: fixed_len_alg)
: Lemma ((block_length a + pow2 32) `less_than_max_input_length` a) | [] | Hacl.HKDF.key_and_data_fits | {
"file_name": "code/hkdf/Hacl.HKDF.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.fixed_len_alg
-> FStar.Pervasives.Lemma
(ensures
Spec.Hash.Definitions.less_than_max_input_length (Spec.Hash.Definitions.block_length a +
Prims.pow2 32)
a) | {
"end_col": 34,
"end_line": 31,
"start_col": 2,
"start_line": 29
} |
Prims.Tot | [
{
"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.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pts_to (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v:a) = to_vprop (pts_to r v) | let pts_to (#a: Type) (#pcm: pcm a) (r: ref a pcm) (v: a) = | false | null | false | to_vprop (pts_to r v) | {
"checked_file": "Steel.PCMReference.fsti.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMReference.fsti"
} | [
"total"
] | [
"FStar.PCM.pcm",
"Steel.Memory.ref",
"Steel.Effect.Common.to_vprop",
"Steel.Memory.pts_to",
"Steel.Effect.Common.vprop"
] | [] | (*
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.PCMReference
open FStar.PCM
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
/// 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__] | false | false | Steel.PCMReference.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pts_to : r: Steel.Memory.ref a pcm -> v: a -> Steel.Effect.Common.vprop | [] | Steel.PCMReference.pts_to | {
"file_name": "lib/steel/Steel.PCMReference.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Memory.ref a pcm -> v: a -> Steel.Effect.Common.vprop | {
"end_col": 77,
"end_line": 35,
"start_col": 56,
"start_line": 35
} |
|
Prims.Tot | [
{
"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.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:erased a)
= squash (forall z. compatible pcm v z ==> fact z) | let fact_valid_compat (#a: Type) (#pcm: pcm a) (fact: stable_property pcm) (v: erased a) = | false | null | false | squash (forall z. compatible pcm v z ==> fact z) | {
"checked_file": "Steel.PCMReference.fsti.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMReference.fsti"
} | [
"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"
] | [] | (*
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.PCMReference
open FStar.PCM
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
/// 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)
/// 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)
: Steel a
(pts_to r v0)
(fun _ -> pts_to r v0)
(requires fun _ -> 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)
: Steel unit
(pts_to r v0)
(fun _ -> pts_to r v1)
(requires fun _ -> 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)
: Steel (ref a pcm)
emp
(fun r -> pts_to r x)
(requires fun _ -> 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)
: Steel unit (pts_to r x) (fun _ -> pts_to r p.p.one)
(requires fun _ -> 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)
: SteelGhost unit inames (pts_to r v)
(fun _ -> pts_to r v0 `star` pts_to r v1)
(requires fun _ ->
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)
: SteelGhostT (_:unit{composable p v0 v1}) inames
(pts_to r v0 `star` pts_to r v1)
(fun _ -> pts_to r (op p v0 v1))
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm) | false | false | Steel.PCMReference.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fact_valid_compat : fact: Steel.Memory.stable_property pcm -> v: FStar.Ghost.erased a -> Type0 | [] | Steel.PCMReference.fact_valid_compat | {
"file_name": "lib/steel/Steel.PCMReference.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | fact: Steel.Memory.stable_property pcm -> v: FStar.Ghost.erased a -> Type0 | {
"end_col": 52,
"end_line": 114,
"start_col": 4,
"start_line": 114
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ctr_t = (p:(int -> vprop) & (x:erased int -> SteelT (y:int{y == x + 1}) (p x) p)) | let ctr_t = | false | null | false | (p: (int -> vprop) & (x: erased int -> SteelT (y: int{y == x + 1}) (p x) p)) | {
"checked_file": "Steel.Closure.fsti.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Closure.fsti"
} | [
"total"
] | [
"Prims.dtuple2",
"Prims.int",
"Steel.Effect.Common.vprop",
"FStar.Ghost.erased",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Ghost.reveal"
] | [] | (*
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.Closure
open Steel.Memory
open Steel.Effect
open FStar.Ghost
/// A small proof-of-concept library showing that vprops can be used inside closures | false | true | Steel.Closure.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ctr_t : Type | [] | Steel.Closure.ctr_t | {
"file_name": "lib/steel/Steel.Closure.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Type | {
"end_col": 85,
"end_line": 25,
"start_col": 12,
"start_line": 25
} |
|
Prims.Tot | val clens_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: parse_bounded_vldata_strong_t min max s) -> (x <: t));
} | val clens_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t)
let clens_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t) = | false | null | false | {
clens_cond = (fun _ -> True);
clens_get = (fun (x: parse_bounded_vldata_strong_t min max s) -> (x <: t))
} | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.Spec.Mkclens",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.l_True",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
= let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x . gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p
inline_for_extraction
let accessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (accessor (gaccessor_bounded_vldata_payload min max p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = slice_access_eq h (gaccessor_bounded_vldata_payload min max p) input pos in
pos `U32.add` U32.uint_to_t (log256' max)
let clens_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t) | [] | LowParse.Low.VLData.clens_bounded_vldata_strong_payload | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p
-> LowParse.Low.Base.Spec.clens (LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s) t | {
"end_col": 77,
"end_line": 782,
"start_col": 2,
"start_line": 781
} |
Prims.Tot | val validate_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(f': (x: bounded_integer sz -> Tot (y: bool{y == f x})))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
() | val validate_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(f': (x: bounded_integer sz -> Tot (y: bool{y == f x})))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
let validate_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(f': (x: bounded_integer sz -> Tot (y: bool{y == f x})))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p)) = | false | null | false | parse_vldata_gen_eq_def sz f p;
validate_filter_and_then (validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_
#_
#(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
() | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"Prims.eq2",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Low.Combinators.validate_filter_and_then",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Low.BoundedInt.validate_bounded_integer",
"LowParse.Low.BoundedInt.read_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.VLData.parse_vldata_payload",
"LowParse.Low.VLData.validate_vldata_payload",
"Prims.unit",
"LowParse.Spec.VLData.parse_vldata_gen_eq_def",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(f': (x: bounded_integer sz -> Tot (y: bool{y == f x})))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p)) | [] | LowParse.Low.VLData.validate_vldata_gen | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (x: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
f': (x: LowParse.Spec.BoundedInt.bounded_integer sz -> y: Prims.bool{y == f x}) ->
v: LowParse.Low.Base.validator p
-> LowParse.Low.Base.validator (LowParse.Spec.VLData.parse_vldata_gen sz f p) | {
"end_col": 6,
"end_line": 40,
"start_col": 2,
"start_line": 32
} |
Prims.Tot | val validate_vldata_payload
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz {f i == true})
: Tot (validator (parse_vldata_payload sz f p i)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) () | val validate_vldata_payload
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz {f i == true})
: Tot (validator (parse_vldata_payload sz f p i))
let validate_vldata_payload
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz {f i == true})
: Tot (validator (parse_vldata_payload sz f p i)) = | false | null | false | validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) () | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"Prims.eq2",
"LowParse.Low.Combinators.validate_weaken",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata",
"LowParse.Low.FLData.validate_fldata",
"LowParse.Spec.VLData.parse_vldata_payload"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } ) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_vldata_payload
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz {f i == true})
: Tot (validator (parse_vldata_payload sz f p i)) | [] | LowParse.Low.VLData.validate_vldata_payload | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (x: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
v: LowParse.Low.Base.validator p ->
i: LowParse.Spec.BoundedInt.bounded_integer sz {f i == true}
-> LowParse.Low.Base.validator (LowParse.Spec.VLData.parse_vldata_payload sz f p i) | {
"end_col": 85,
"end_line": 20,
"start_col": 2,
"start_line": 20
} |
Prims.Tot | val jump_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos) | val jump_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
let jump_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` ((U32.uint_to_t sz) `U32.add` (read_bounded_integer sz input pos)) | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Low.BoundedInt.read_bounded_integer",
"Prims.unit",
"LowParse.Low.VLData.valid_vldata_gen_elim",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.jumper",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_vldata_gen
(sz: integer_size)
(f: (x: bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p)) | [] | LowParse.Low.VLData.jump_vldata_gen | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (x: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t
-> LowParse.Low.Base.jumper (LowParse.Spec.VLData.parse_vldata_gen sz f p) | {
"end_col": 78,
"end_line": 91,
"start_col": 2,
"start_line": 88
} |
Prims.Tot | val validate_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata_strong min max s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v | val validate_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata_strong min max s))
let validate_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata_strong min max s)) = | false | null | false | validate_bounded_vldata_strong' min max (log256' max) s v | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.validator",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Low.VLData.validate_bounded_vldata_strong'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata_strong min max s)) | [] | LowParse.Low.VLData.validate_bounded_vldata_strong | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
v: LowParse.Low.Base.validator p ->
u78: u79: Prims.unit{min <= max /\ max > 0 /\ max < 4294967296}
-> LowParse.Low.Base.validator (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s) | {
"end_col": 59,
"end_line": 201,
"start_col": 2,
"start_line": 201
} |
Prims.Tot | val validate_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata min max p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v | val validate_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata min max p))
let validate_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata min max p)) = | false | null | false | validate_bounded_vldata' min max (log256' max) v | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Low.VLData.validate_bounded_vldata'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (validator (parse_bounded_vldata min max p)) | [] | LowParse.Low.VLData.validate_bounded_vldata | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat ->
v: LowParse.Low.Base.validator p ->
u49: u50: Prims.unit{min <= max /\ max > 0 /\ max < 4294967296}
-> LowParse.Low.Base.validator (LowParse.Spec.VLData.parse_bounded_vldata min max p) | {
"end_col": 50,
"end_line": 130,
"start_col": 2,
"start_line": 130
} |
Prims.Tot | val jump_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata min max p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p | val jump_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata min max p))
let jump_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata min max p)) = | false | null | false | jump_bounded_vldata' min max (log256' max) p | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Low.VLData.jump_bounded_vldata'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Low.Base.jumper",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_bounded_vldata
(min max: nat)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata min max p)) | [] | LowParse.Low.VLData.jump_bounded_vldata | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat ->
p: LowParse.Spec.Base.parser k t ->
u60: u61: Prims.unit{min <= max /\ max > 0 /\ max < 4294967296}
-> LowParse.Low.Base.jumper (LowParse.Spec.VLData.parse_bounded_vldata min max p) | {
"end_col": 46,
"end_line": 165,
"start_col": 2,
"start_line": 165
} |
Prims.Tot | val jump_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata_strong min max s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s | val jump_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata_strong min max s))
let jump_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata_strong min max s)) = | false | null | false | jump_bounded_vldata_strong' min max (log256' max) s | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Low.VLData.jump_bounded_vldata_strong'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Low.Base.jumper",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_bounded_vldata_strong
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit{min <= max /\ max > 0 /\ max < 4294967296})
: Tot (jumper (parse_bounded_vldata_strong min max s)) | [] | LowParse.Low.VLData.jump_bounded_vldata_strong | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
u91: u92: Prims.unit{min <= max /\ max > 0 /\ max < 4294967296}
-> LowParse.Low.Base.jumper (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s) | {
"end_col": 53,
"end_line": 233,
"start_col": 2,
"start_line": 233
} |
Prims.Tot | val gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
(gaccessor_bounded_vldata_payload min max p input <: (res : _ { gaccessor_post' (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s) input res } )) | val gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s))
let gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)) = | false | null | false | fun input ->
(gaccessor_bounded_vldata_payload min max p input
<:
(res:
_
{ gaccessor_post' (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)
input
res })) | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Bytes.bytes",
"LowParse.Low.VLData.gaccessor_bounded_vldata_payload",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Low.Base.Spec.gaccessor'"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
= let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x . gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p
inline_for_extraction
let accessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (accessor (gaccessor_bounded_vldata_payload min max p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = slice_access_eq h (gaccessor_bounded_vldata_payload min max p) input pos in
pos `U32.add` U32.uint_to_t (log256' max)
let clens_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: parse_bounded_vldata_strong_t min max s) -> (x <: t));
}
let gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)) | [] | LowParse.Low.VLData.gaccessor_bounded_vldata_strong_payload' | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s) | {
"end_col": 186,
"end_line": 794,
"start_col": 2,
"start_line": 793
} |
FStar.Pervasives.Lemma | val valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_vldata_gen sz f p) h input pos))
(ensures
(valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_vldata_gen sz f p) h input pos)))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload) | val valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_vldata_gen sz f p) h input pos))
(ensures
(valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_vldata_gen sz f p) h input pos))))
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_vldata_gen sz f p) h input pos))
(ensures
(valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_vldata_gen sz f p) h input pos)))) = | false | null | true | valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload) | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.contents_exact_eq",
"FStar.UInt32.add",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_exact_equiv",
"FStar.UInt32.uint_to_t",
"LowParse.Low.Base.Spec.contents",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 4,
"max_fuel": 8,
"max_ifuel": 4,
"no_plugins": false,
"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": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_vldata_gen sz f p) h input pos))
(ensures
(valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_vldata_gen sz f p) h input pos)))) | [] | LowParse.Low.VLData.valid_vldata_gen_elim | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLData.parse_vldata_gen sz f p) h input pos)
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos /\
(let len_payload =
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos
in
f len_payload == true /\
sz + FStar.UInt32.v len_payload ==
LowParse.Low.Base.Spec.content_length (LowParse.Spec.VLData.parse_vldata_gen sz f p)
h
input
pos /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.VLData.parse_vldata_gen sz f p)
h
input
pos
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.valid_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.contents_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) ==
LowParse.Low.Base.Spec.contents (LowParse.Spec.VLData.parse_vldata_gen sz f p)
h
input
pos))) | {
"end_col": 77,
"end_line": 76,
"start_col": 2,
"start_line": 70
} |
Prims.Tot | val gaccessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
= let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x . gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p | val gaccessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t)) = | false | null | false | let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x.
gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p)
p
(clens_id t)
(gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.VLData.gaccessor_bounded_vldata_payload'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata",
"LowParse.Low.Base.Spec.clens_id",
"Prims._assert",
"Prims.l_Forall",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"Prims.l_imp",
"LowParse.Low.Base.Spec.gaccessor_pre",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Classical.forall_intro",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.BoundedInt.in_bounds",
"FStar.Pervasives.Native.None",
"Prims.l_or",
"Prims.op_Addition",
"FStar.UInt32.v",
"Prims.bool",
"FStar.Seq.Base.slice",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Pervasives.Native.Mktuple2",
"Prims.logical",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong }) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t)) | [] | LowParse.Low.VLData.gaccessor_bounded_vldata_payload | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p:
LowParse.Spec.Base.parser k t
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.VLData.parse_bounded_vldata min max p)
p
(LowParse.Low.Base.Spec.clens_id t) | {
"end_col": 45,
"end_line": 755,
"start_col": 1,
"start_line": 751
} |
Prims.Tot | val jump_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos | val jump_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
let jump_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let sz = l in
[@@ inline_let ]let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@@ inline_let ]let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.jump_vldata_gen",
"LowParse.Spec.BoundedInt.in_bounds",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata'",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.jumper"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p)) | [] | LowParse.Low.VLData.jump_bounded_vldata' | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} ->
p: LowParse.Spec.Base.parser k t
-> LowParse.Low.Base.jumper (LowParse.Spec.VLData.parse_bounded_vldata' min max l p) | {
"end_col": 52,
"end_line": 150,
"start_col": 2,
"start_line": 145
} |
FStar.HyperStack.ST.Stack | val finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ f len_payload == true))))
(ensures
(fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_vldata_gen sz f p)
h'
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos' | val finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ f len_payload == true))))
(ensures
(fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_vldata_gen sz f p)
h'
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos'))
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ f len_payload == true))))
(ensures
(fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_vldata_gen sz f p)
h'
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) = | true | null | false | [@@ inline_let ]let len_payload = pos' `U32.sub` (pos `U32.add` (U32.uint_to_t sz)) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_vldata_gen_intro",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.BoundedInt.write_bounded_integer",
"FStar.UInt32.sub",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Spec.BoundedInt.bounded_integer_prop",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.eq2",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Low.Base.Spec.contents_exact"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ f len_payload == true))))
(ensures
(fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_vldata_gen sz f p)
h'
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) | [] | LowParse.Low.VLData.finalize_vldata_gen | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 48,
"end_line": 298,
"start_col": 2,
"start_line": 294
} |
FStar.HyperStack.ST.Stack | val weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ k.parser_kind_subkind == Some ParserStrong /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos' | val weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ k.parser_kind_subkind == Some ParserStrong /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True)))
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ k.parser_kind_subkind == Some ParserStrong /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True))) = | true | null | false | let h = HST.get () in
[@@ inline_let ]let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.weak_finalize_bounded_vldata_strong_exact",
"Prims.bool",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_pos_valid_exact",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.valid_pos",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"Prims.l_iff",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.Base.Spec.contents",
"Prims.l_True",
"Prims.logical",
"FStar.UInt32.sub"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ k.parser_kind_subkind == Some ParserStrong /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True))) | [] | LowParse.Low.VLData.weak_finalize_bounded_vldata_strong | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 68,
"end_line": 717,
"start_col": 1,
"start_line": 710
} |
Prims.Tot | val jump_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos | val jump_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
let jump_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s)) = | false | null | false | fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@@ inline_let ]let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.jump_bounded_vldata'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong'",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.jumper"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s)) | [] | LowParse.Low.VLData.jump_bounded_vldata_strong' | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} ->
s: LowParse.Spec.Base.serializer p
-> LowParse.Low.Base.jumper (LowParse.Spec.VLData.parse_bounded_vldata_strong' min max l s) | {
"end_col": 44,
"end_line": 219,
"start_col": 2,
"start_line": 215
} |
FStar.HyperStack.ST.Stack | val finalize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos' | val finalize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'))
let finalize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos')) = | true | null | false | finalize_bounded_vldata_exact min max p input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.finalize_bounded_vldata_exact",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_pos",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.uu___is_Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata",
"LowParse.Low.Base.Spec.contents"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos')) | [] | LowParse.Low.VLData.finalize_bounded_vldata | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 56,
"end_line": 633,
"start_col": 2,
"start_line": 633
} |
Prims.Tot | val accessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_payload min max p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (accessor (gaccessor_bounded_vldata_payload min max p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = slice_access_eq h (gaccessor_bounded_vldata_payload min max p) input pos in
pos `U32.add` U32.uint_to_t (log256' max) | val accessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_payload min max p))
let accessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_payload min max p)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_bounded_vldata_payload min max p) input pos
in
pos `U32.add` (U32.uint_to_t (log256' max)) | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata",
"LowParse.Low.Base.Spec.clens_id",
"LowParse.Low.VLData.gaccessor_bounded_vldata_payload",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
= let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x . gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p
inline_for_extraction
let accessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong }) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_bounded_vldata_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_payload min max p)) | [] | LowParse.Low.VLData.accessor_bounded_vldata_payload | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p:
LowParse.Spec.Base.parser k t
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.accessor (LowParse.Low.VLData.gaccessor_bounded_vldata_payload min max p) | {
"end_col": 43,
"end_line": 769,
"start_col": 2,
"start_line": 765
} |
FStar.HyperStack.ST.Stack | val finalize_bounded_vldata_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos' | val finalize_bounded_vldata_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'))
let finalize_bounded_vldata_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos')) = | true | null | false | [@@ inline_let ]let sz = log256' max in
[@@ inline_let ]let len_payload = pos' `U32.sub` (pos `U32.add` (U32.uint_to_t sz)) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_bounded_vldata_intro",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.BoundedInt.write_bounded_integer",
"FStar.UInt32.sub",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.uu___is_Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.__proj__Some__item__v",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata",
"LowParse.Low.Base.Spec.contents_exact"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_bounded_vldata_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\ min <= k.parser_kind_low /\
Some? k.parser_kind_high /\ Some?.v k.parser_kind_high <= max)))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos')) | [] | LowParse.Low.VLData.finalize_bounded_vldata_exact | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 55,
"end_line": 602,
"start_col": 2,
"start_line": 595
} |
Prims.Tot | val gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz | val gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t)) = | false | null | false | fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0
else
let _ =
match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p
(Seq.slice input sz (sz + U32.v len))
(Seq.slice input sz (Seq.length input))
in
sz | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Bytes.bytes",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.bool",
"Prims.unit",
"LowParse.Spec.Base.parse",
"LowParse.Spec.VLData.parse_bounded_vldata",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.Base.parse_strong_prefix",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.UInt32.v",
"Prims._assert",
"Prims.l_or",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Spec.BoundedInt.in_bounds",
"FStar.Pervasives.Native.uu___is_Some",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Low.Base.Spec.clens_id"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong }) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t)) | [] | LowParse.Low.VLData.gaccessor_bounded_vldata_payload' | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p:
LowParse.Spec.Base.parser k t
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.VLData.parse_bounded_vldata min max p)
p
(LowParse.Low.Base.Spec.clens_id t) | {
"end_col": 6,
"end_line": 742,
"start_col": 2,
"start_line": 727
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong min max s) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong min max s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong min max s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong min max s) h input pos)))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos | val valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong min max s) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong min max s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong min max s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong min max s) h input pos))))
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong min max s) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong min max s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong min max s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong min max s) h input pos)))) = | false | null | true | valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_bounded_vldata_strong'_elim",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"Prims.squash",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.UInt32.v",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid_pos",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.contents_exact",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong min max s) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong min max s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong min max s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong min max s) h input pos)))) | [] | LowParse.Low.VLData.valid_bounded_vldata_strong_elim | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s)
h
input
pos)
(ensures
(let sz = LowParse.Spec.BoundedInt.log256' max in
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
(let len_payload =
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos
in
min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\
sz + FStar.UInt32.v len_payload ==
LowParse.Low.Base.Spec.content_length (LowParse.Spec.VLData.parse_bounded_vldata_strong min
max
s)
h
input
pos /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.VLData.parse_bounded_vldata_strong min
max
s)
h
input
pos
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.valid_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.contents_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) ==
LowParse.Low.Base.Spec.contents (LowParse.Spec.VLData.parse_bounded_vldata_strong min
max
s)
h
input
pos)))) | {
"end_col": 71,
"end_line": 445,
"start_col": 2,
"start_line": 445
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' | val valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'))
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos')) = | false | null | true | valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Low.VLData.valid_bounded_vldata_intro",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.sub",
"LowParse.Spec.BoundedInt.integer_size",
"Prims.squash",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"Prims.op_Subtraction",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos')) | [] | LowParse.Low.VLData.valid_bounded_vldata_strong_intro | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
(let sz = LowParse.Spec.BoundedInt.log256' max in
FStar.UInt32.v pos + sz <= FStar.UInt32.v (Mkslice?.len input) /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_exact p h input pos_payload pos' /\
(let len_payload = FStar.UInt32.sub pos' pos_payload in
min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos ==
len_payload))))
(ensures
(let sz = LowParse.Spec.BoundedInt.log256' max in
let x =
LowParse.Low.Base.Spec.contents_exact p
h
input
(FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz))
pos'
in
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) ==
FStar.UInt32.v pos' - (FStar.UInt32.v pos + sz) /\
LowParse.Spec.VLData.parse_bounded_vldata_strong_pred min max s x /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLData.parse_bounded_vldata_strong
min
max
s)
h
input
pos
x
pos')) | {
"end_col": 82,
"end_line": 480,
"start_col": 2,
"start_line": 477
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata min max p) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata min max p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata min max p) h input pos)))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos | val valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata min max p) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata min max p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata min max p) h input pos))))
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata min max p) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata min max p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata min max p) h input pos)))) = | false | null | true | valid_bounded_vldata'_elim h min max (log256' max) p input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_bounded_vldata'_elim",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata",
"Prims.squash",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.UInt32.v",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid_pos",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.contents_exact",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata min max p) h input pos))
(ensures
(let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata min max p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata min max p) h input pos)))) | [] | LowParse.Low.VLData.valid_bounded_vldata_elim | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLData.parse_bounded_vldata min max p)
h
input
pos)
(ensures
(let sz = LowParse.Spec.BoundedInt.log256' max in
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
(let len_payload =
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos
in
min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\
sz + FStar.UInt32.v len_payload ==
LowParse.Low.Base.Spec.content_length (LowParse.Spec.VLData.parse_bounded_vldata min
max
p)
h
input
pos /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.VLData.parse_bounded_vldata min max p)
h
input
pos
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.valid_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.contents_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) ==
LowParse.Low.Base.Spec.contents (LowParse.Spec.VLData.parse_bounded_vldata min max p)
h
input
pos)))) | {
"end_col": 64,
"end_line": 356,
"start_col": 2,
"start_line": 356
} |
FStar.Pervasives.Lemma | val valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\ f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(valid_content_pos (parse_vldata_gen sz f p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos' | val valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\ f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(valid_content_pos (parse_vldata_gen sz f p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos'))
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\ f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(valid_content_pos (parse_vldata_gen sz f p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) = | false | null | true | valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` (U32.uint_to_t sz)) pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.contents_exact_eq",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"Prims.unit",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Spec.BoundedInt.bounded_integer_prop",
"Prims.eq2",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.sub",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 4,
"max_fuel": 8,
"max_ifuel": 4,
"no_plugins": false,
"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": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\ f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(valid_content_pos (parse_vldata_gen sz f p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) | [] | LowParse.Low.VLData.valid_vldata_gen_intro | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
FStar.UInt32.v pos + sz <= FStar.UInt32.v (Mkslice?.len input) /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_exact p h input pos_payload pos' /\
(let len_payload = FStar.UInt32.sub pos' pos_payload in
LowParse.Spec.BoundedInt.bounded_integer_prop sz len_payload /\ f len_payload == true /\
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos ==
len_payload)))
(ensures
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLData.parse_vldata_gen sz f p)
h
input
pos
(LowParse.Low.Base.Spec.contents_exact p
h
input
(FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz))
pos')
pos') | {
"end_col": 67,
"end_line": 265,
"start_col": 2,
"start_line": 262
} |
FStar.HyperStack.ST.Stack | val finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos' | val finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'))
let finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos')) = | true | null | false | let h = HST.get () in
[@@ inline_let ]let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.finalize_bounded_vldata_strong_exact",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_pos_valid_exact",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_pos",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.l_or",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.sub",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` (U32.uint_to_t sz)) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos')) | [] | LowParse.Low.VLData.finalize_bounded_vldata_strong | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 63,
"end_line": 565,
"start_col": 1,
"start_line": 558
} |
Prims.Tot | val accessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_strong_payload min max s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_strong_payload min max s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = slice_access_eq h (gaccessor_bounded_vldata_strong_payload min max s) input pos in
pos `U32.add` U32.uint_to_t (log256' max) | val accessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_strong_payload min max s))
let accessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_strong_payload min max s)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_bounded_vldata_strong_payload min max s) input pos
in
pos `U32.add` (U32.uint_to_t (log256' max)) | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Low.VLData.gaccessor_bounded_vldata_strong_payload",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
= let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x . gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p
inline_for_extraction
let accessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (accessor (gaccessor_bounded_vldata_payload min max p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = slice_access_eq h (gaccessor_bounded_vldata_payload min max p) input pos in
pos `U32.add` U32.uint_to_t (log256' max)
let clens_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: parse_bounded_vldata_strong_t min max s) -> (x <: t));
}
let gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
(gaccessor_bounded_vldata_payload min max p input <: (res : _ { gaccessor_post' (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s) input res } ))
let gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s))
= gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_prop_equiv (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vldata_strong_payload' min max s);
gaccessor_bounded_vldata_strong_payload' min max s
inline_for_extraction
let accessor_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vldata_strong_payload min max s)) | [] | LowParse.Low.VLData.accessor_bounded_vldata_strong_payload | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.accessor (LowParse.Low.VLData.gaccessor_bounded_vldata_strong_payload min
max
s) | {
"end_col": 43,
"end_line": 821,
"start_col": 2,
"start_line": 817
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos' | val valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos'))
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) = | false | null | true | valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_vldata_gen_intro",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.BoundedInt.in_bounds",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.sub",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.integer_size",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload))))
(ensures
(let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p)
h
input
pos
(contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos')
pos')) | [] | LowParse.Low.VLData.valid_bounded_vldata_intro | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
(let sz = LowParse.Spec.BoundedInt.log256' max in
FStar.UInt32.v pos + sz <= FStar.UInt32.v (Mkslice?.len input) /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_exact p h input pos_payload pos' /\
(let len_payload = FStar.UInt32.sub pos' pos_payload in
min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos ==
len_payload))))
(ensures
(let sz = LowParse.Spec.BoundedInt.log256' max in
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLData.parse_bounded_vldata min
max
p)
h
input
pos
(LowParse.Low.Base.Spec.contents_exact p
h
input
(FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz))
pos')
pos')) | {
"end_col": 77,
"end_line": 386,
"start_col": 2,
"start_line": 384
} |
Prims.Tot | val validate_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos | val validate_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
let validate_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos)
in
[@@ inline_let ]let _ =
valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos)
in
validate_bounded_vldata' min max l v input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.validator",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.VLData.validate_bounded_vldata'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata'",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong'",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_bounded_vldata_strong'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s)) | [] | LowParse.Low.VLData.validate_bounded_vldata_strong' | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} ->
s: LowParse.Spec.Base.serializer p ->
v: LowParse.Low.Base.validator p
-> LowParse.Low.Base.validator (LowParse.Spec.VLData.parse_bounded_vldata_strong' min max l s) | {
"end_col": 48,
"end_line": 186,
"start_col": 2,
"start_line": 180
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata' min max l p) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata' min max l p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata' min max l p) h input pos)))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos | val valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata' min max l p) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata' min max l p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata' min max l p) h input pos))))
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata' min max l p) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata' min max l p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata' min max l p) h input pos)))) = | false | null | true | valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_vldata_gen_elim",
"LowParse.Spec.BoundedInt.in_bounds",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata'",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.UInt32.v",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid_pos",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.contents_exact",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.uint_to_t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata' min max l p) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata' min max l p)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata' min max l p) h input pos)))) | [] | LowParse.Low.VLData.valid_bounded_vldata'_elim | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLData.parse_bounded_vldata' min max l p)
h
input
pos)
(ensures
(let sz = l in
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
(let len_payload =
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos
in
min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\
sz + FStar.UInt32.v len_payload ==
LowParse.Low.Base.Spec.content_length (LowParse.Spec.VLData.parse_bounded_vldata' min
max
l
p)
h
input
pos /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.VLData.parse_bounded_vldata' min
max
l
p)
h
input
pos
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.valid_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.contents_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) ==
LowParse.Low.Base.Spec.contents (LowParse.Spec.VLData.parse_bounded_vldata' min
max
l
p)
h
input
pos)))) | {
"end_col": 60,
"end_line": 329,
"start_col": 2,
"start_line": 326
} |
Prims.Tot | val gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s))
= gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_prop_equiv (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vldata_strong_payload' min max s);
gaccessor_bounded_vldata_strong_payload' min max s | val gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s))
let gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)) = | false | null | false | gaccessor_prop_equiv (parse_bounded_vldata min max p)
p
(clens_id t)
(gaccessor_bounded_vldata_payload' min max p);
gaccessor_prop_equiv (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)
(gaccessor_bounded_vldata_strong_payload' min max s);
gaccessor_bounded_vldata_strong_payload' min max s | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.VLData.gaccessor_bounded_vldata_strong_payload'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Spec.VLData.parse_bounded_vldata",
"LowParse.Low.Base.Spec.clens_id",
"LowParse.Low.VLData.gaccessor_bounded_vldata_payload'",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end
inline_for_extraction
let weak_finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
k.parser_kind_subkind == Some ParserStrong /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_pos p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents p h input pos_payload in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
weak_finalize_bounded_vldata_strong_exact min max s input pos pos'
let gaccessor_bounded_vldata_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor' (parse_bounded_vldata min max p) p (clens_id t))
= fun input ->
let sz = log256' max in
parse_vldata_gen_eq sz (in_bounds min max) p input;
if Seq.length input < sz
then 0 (* dummy *)
else
let _ = match parse (parse_bounded_vldata min max p) input with
| None -> ()
| Some _ ->
assert (Some? (parse (parse_vldata_gen sz (in_bounds min max) p) input));
parse_vldata_gen_eq sz (in_bounds min max) p input;
let Some (len, consumed) = parse (parse_bounded_integer sz) input in
assert (consumed == sz);
parse_strong_prefix p (Seq.slice input sz (sz + U32.v len)) (Seq.slice input sz (Seq.length input))
in
sz
let gaccessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (gaccessor (parse_bounded_vldata min max p) p (clens_id t))
= let sz = log256' max in
Classical.forall_intro (parse_vldata_gen_eq sz (in_bounds min max) p);
assert (forall x . gaccessor_pre (parse_bounded_vldata min max p) p (clens_id t) x ==> Seq.length x >= sz);
gaccessor_prop_equiv (parse_bounded_vldata min max p) p (clens_id t) (gaccessor_bounded_vldata_payload' min max p);
gaccessor_bounded_vldata_payload' min max p
inline_for_extraction
let accessor_bounded_vldata_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t { k.parser_kind_subkind == Some ParserStrong })
: Tot (accessor (gaccessor_bounded_vldata_payload min max p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = slice_access_eq h (gaccessor_bounded_vldata_payload min max p) input pos in
pos `U32.add` U32.uint_to_t (log256' max)
let clens_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (clens (parse_bounded_vldata_strong_t min max s) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (x: parse_bounded_vldata_strong_t min max s) -> (x <: t));
}
let gaccessor_bounded_vldata_strong_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
(gaccessor_bounded_vldata_payload min max p input <: (res : _ { gaccessor_post' (parse_bounded_vldata_strong min max s) p (clens_bounded_vldata_strong_payload min max s) input res } ))
let gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong}) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_bounded_vldata_strong_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vldata_strong min max s)
p
(clens_bounded_vldata_strong_payload min max s)) | [] | LowParse.Low.VLData.gaccessor_bounded_vldata_strong_payload | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s) | {
"end_col": 52,
"end_line": 806,
"start_col": 2,
"start_line": 804
} |
FStar.HyperStack.ST.Stack | val weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True
)))
= let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t (log256' max)) in
if U32.uint_to_t max `U32.lt` len_payload || len_payload `U32.lt` U32.uint_to_t min
then false
else begin
finalize_bounded_vldata_strong_exact min max s input pos pos';
true
end | val weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True)))
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True))) = | true | null | false | let len_payload = pos' `U32.sub` (pos `U32.add` (U32.uint_to_t (log256' max))) in
if (U32.uint_to_t max) `U32.lt` len_payload || len_payload `U32.lt` (U32.uint_to_t min)
then false
else
(finalize_bounded_vldata_strong_exact min max s input pos pos';
true) | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_BarBar",
"FStar.UInt32.lt",
"FStar.UInt32.uint_to_t",
"Prims.bool",
"Prims.unit",
"LowParse.Low.VLData.finalize_bounded_vldata_strong_exact",
"FStar.UInt32.sub",
"FStar.UInt32.add",
"LowParse.Spec.BoundedInt.log256'",
"FStar.Monotonic.HyperStack.mem",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Spec.BoundedInt.integer_size",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"Prims.l_iff",
"Prims.eq2",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.l_True",
"Prims.logical"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vldata_strong_exact min max s input pos pos'
inline_for_extraction
let finalize_bounded_vldata_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_intro h min max p input pos pos'
inline_for_extraction
let finalize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
min <= k.parser_kind_low /\
Some? k.parser_kind_high /\
Some?.v k.parser_kind_high <= max
)))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents p h input (pos `U32.add` U32.uint_to_t sz) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_bounded_vldata min max p) h' input pos x pos'
))
= finalize_bounded_vldata_exact min max p input pos pos'
inline_for_extraction
let weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack bool
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos'
)))
(ensures (fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val weak_finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
valid_exact p h input pos_payload pos')))
(ensures
(fun h res h' ->
let sz = log256' max in
let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
let len_payload = pos' `U32.sub` pos_payload in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
(res == true <==> (min <= U32.v len_payload /\ U32.v len_payload <= max)) /\
(if res
then
let x = contents_exact p h input pos_payload pos' in
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
else True))) | [] | LowParse.Low.VLData.weak_finalize_bounded_vldata_strong_exact | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 674,
"start_col": 1,
"start_line": 668
} |
Prims.Tot | val validate_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
() | val validate_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
let validate_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p)) = | false | null | false | [@@ inline_let ]let sz:integer_size = l in
[@@ inline_let ]let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen (parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz
(in_bounds min max)
(fun i ->
if min = 0
then i `U32.lte` (U32.uint_to_t max)
else ((U32.uint_to_t min) `U32.lte` i && i `U32.lte` (U32.uint_to_t max)))
v)
() | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Low.Combinators.validate_strengthen",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.BoundedInt.in_bounds",
"LowParse.Low.VLData.validate_vldata_gen",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt32.lte",
"FStar.UInt32.uint_to_t",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.eq2",
"Prims.unit",
"LowParse.Spec.VLData.parse_bounded_vldata_correct",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.VLData.parse_bounded_vldata'"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p) | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p)) | [] | LowParse.Low.VLData.validate_bounded_vldata' | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} ->
v: LowParse.Low.Base.validator p
-> LowParse.Low.Base.validator (LowParse.Spec.VLData.parse_bounded_vldata' min max l p) | {
"end_col": 6,
"end_line": 114,
"start_col": 2,
"start_line": 107
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong' min max l s) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong' min max l s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong' min max l s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong' min max l s) h input pos)))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos | val valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong' min max l s) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong' min max l s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong' min max l s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong' min max l s) h input pos))))
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong' min max l s) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong' min max l s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong' min max l s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong' min max l s) h input pos)))) = | false | null | true | valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_bounded_vldata'_elim",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong'",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.UInt32.v",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid_pos",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.contents_exact",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.uint_to_t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(l: nat{l >= log256' max /\ l <= 4})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_bounded_vldata_strong' min max l s) h input pos))
(ensures
(let sz = l in
valid (parse_bounded_integer sz) h input pos /\
(let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload ==
content_length (parse_bounded_vldata_strong' min max l s) h input pos /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos (parse_bounded_vldata_strong' min max l s)
h
input
pos
(pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) ==
contents (parse_bounded_vldata_strong' min max l s) h input pos)))) | [] | LowParse.Low.VLData.valid_bounded_vldata_strong'_elim | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLData.parse_bounded_vldata_strong' min max l s)
h
input
pos)
(ensures
(let sz = l in
LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos /\
(let len_payload =
LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
h
input
pos
in
min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\
sz + FStar.UInt32.v len_payload ==
LowParse.Low.Base.Spec.content_length (LowParse.Spec.VLData.parse_bounded_vldata_strong'
min
max
l
s)
h
input
pos /\
(let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in
LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.VLData.parse_bounded_vldata_strong' min
max
l
s)
h
input
pos
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.valid_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) /\
LowParse.Low.Base.Spec.contents_exact p
h
input
pos_payload
(FStar.UInt32.add pos_payload len_payload) ==
LowParse.Low.Base.Spec.contents (LowParse.Spec.VLData.parse_bounded_vldata_strong' min
max
l
s)
h
input
pos)))) | {
"end_col": 52,
"end_line": 417,
"start_col": 2,
"start_line": 415
} |
FStar.HyperStack.ST.Stack | val finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'
))
= [@inline_let]
let sz = log256' max in
[@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos');
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t sz) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos' | val finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos'))
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos')) = | true | null | false | [@@ inline_let ]let sz = log256' max in
[@@ inline_let ]let len_payload = pos' `U32.sub` (pos `U32.add` (U32.uint_to_t sz)) in
let h = HST.get () in
[@@ inline_let ]let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos');
valid_exact_serialize s h input (pos `U32.add` (U32.uint_to_t sz)) pos'
in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_bounded_vldata_strong_intro h min max s input pos pos' | {
"checked_file": "LowParse.Low.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLData.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.valid_bounded_vldata_strong_intro",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.BoundedInt.write_bounded_integer",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Base.Spec.contents_exact",
"FStar.UInt32.sub",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.l_or",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"Prims.eq2",
"Prims.int",
"Prims.op_Subtraction",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong"
] | [] | module LowParse.Low.VLData
include LowParse.Spec.VLData
include LowParse.Low.BoundedInt // for bounded_integer
include LowParse.Low.FLData
module B = LowStar.Buffer
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
inline_for_extraction
let validate_vldata_payload
(sz: integer_size)
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(i: bounded_integer sz { f i == true } )
: Tot (validator (parse_vldata_payload sz f p i))
= validate_weaken (parse_vldata_payload_kind sz k) (validate_fldata v (U32.v i) i) ()
inline_for_extraction
let validate_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(f' : ((x: bounded_integer sz) -> Tot (y: bool { y == f x })))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_vldata_gen sz f p))
= parse_vldata_gen_eq_def sz f p;
validate_filter_and_then
(validate_bounded_integer sz)
(read_bounded_integer sz)
f
f'
#_ #_ #(parse_vldata_payload sz f p)
(validate_vldata_payload sz f v)
()
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
module HS = FStar.HyperStack
let valid_vldata_gen_elim
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_vldata_gen sz f p) h input pos
))
(ensures (
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
f len_payload == true /\
sz + U32.v len_payload == content_length (parse_vldata_gen sz f p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_vldata_gen sz f p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_vldata_gen sz f p) h input pos
))))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
let len_payload = contents (parse_bounded_integer sz) h input pos in
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact_equiv p h input pos_payload (pos_payload `U32.add` len_payload);
contents_exact_eq p h input pos_payload (pos_payload `U32.add` len_payload)
#pop-options
inline_for_extraction
let jump_vldata_gen
(sz: integer_size) // must be a constant
(f: ((x: bounded_integer sz) -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_vldata_gen sz f p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_vldata_gen_elim h sz f p input pos in
pos `U32.add` (U32.uint_to_t sz `U32.add` read_bounded_integer sz input pos)
inline_for_extraction
let validate_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator (parse_bounded_vldata' min max l p))
= [@inline_let]
let sz : integer_size = l in
[@inline_let]
let _ = parse_bounded_vldata_correct min max sz p in
validate_strengthen
(parse_bounded_vldata_strong_kind min max sz k)
(validate_vldata_gen sz (in_bounds min max) (fun i -> if min = 0 then i `U32.lte` U32.uint_to_t max else (U32.uint_to_t min `U32.lte` i && i `U32.lte` U32.uint_to_t max)) v)
()
inline_for_extraction
let validate_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (validator (parse_bounded_vldata min max p))
= validate_bounded_vldata' min max (log256' max) v
inline_for_extraction
let jump_bounded_vldata'
(min: nat) // must be a constant
(max: nat {
min <= max /\
max > 0 /\
max < 4294967296
}) // must be a constant
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (jumper (parse_bounded_vldata' min max l p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let sz = l in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
[@inline_let] let _ = valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos in
jump_vldata_gen sz (in_bounds min max) p input pos
inline_for_extraction
let jump_bounded_vldata
(min: nat) // must be a constant
(max: nat) // must be a constant
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(u: unit {
min <= max /\
max > 0 /\
max < 4294967296
})
: Tot (jumper (parse_bounded_vldata min max p))
= jump_bounded_vldata' min max (log256' max) p
inline_for_extraction
let validate_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts (parse_bounded_vldata' min max l p) h input (uint64_to_uint32 pos) in
validate_bounded_vldata' min max l v input pos
inline_for_extraction
let validate_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (validator (parse_bounded_vldata_strong min max s))
= validate_bounded_vldata_strong' min max (log256' max) s v
inline_for_extraction
let jump_bounded_vldata_strong'
(min: nat) // must be a constant
(max: nat {
min <= max /\ max > 0 /\ max < 4294967296
})
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vldata_strong' min max l s))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_bounded_vldata_strong' min max l s) h input pos in
[@inline_let] let _ = valid_facts (parse_bounded_vldata' min max l p) h input pos in
jump_bounded_vldata' min max l p input pos
inline_for_extraction
let jump_bounded_vldata_strong
(min: nat) // must be a constant
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(u: unit {
min <= max /\ max > 0 /\ max < 4294967296
})
: Tot (jumper (parse_bounded_vldata_strong min max s))
= jump_bounded_vldata_strong' min max (log256' max) s
#push-options "--z3rlimit 32 --initial_ifuel 4 --max_ifuel 4"
let valid_vldata_gen_intro
(h: HS.mem)
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
f len_payload == true /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
valid_content_pos (parse_vldata_gen sz f p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_vldata_gen sz f p) h input pos;
valid_facts (parse_bounded_integer sz) h input pos;
parse_vldata_gen_eq sz f p (bytes_of_slice_from h input pos);
contents_exact_eq p h input (pos `U32.add` U32.uint_to_t sz) pos'
#pop-options
inline_for_extraction
let finalize_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
bounded_integer_prop sz len_payload /\
writable input.base (U32.v pos) (U32.v pos + sz) h /\
f len_payload == true
))))
(ensures (fun h _ h' ->
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
valid_content_pos (parse_vldata_gen sz f p) h' input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` U32.uint_to_t sz) in
let _ = write_bounded_integer sz len_payload input pos in
let h = HST.get () in
valid_vldata_gen_intro h sz f p input pos pos'
let valid_bounded_vldata'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata' min max l p) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata' min max l p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata' min max l p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata' min max l p) h input pos
))))
= valid_facts (parse_bounded_vldata' min max l p) h input pos;
let sz = l in
valid_facts (parse_vldata_gen sz (in_bounds min max) p) h input pos;
valid_vldata_gen_elim h sz (in_bounds min max) p input pos
let valid_bounded_vldata_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata min max p) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata min max p) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata min max p) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata min max p) h input pos
))))
= valid_bounded_vldata'_elim h min max (log256' max) p input pos
let valid_bounded_vldata_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
valid_content_pos (parse_bounded_vldata min max p) h input pos (contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos') pos'
))
= valid_facts (parse_bounded_vldata min max p) h input pos;
valid_facts (parse_vldata_gen (log256' max) (in_bounds min max) p) h input pos;
valid_vldata_gen_intro h (log256' max) (in_bounds min max) p input pos pos'
let valid_bounded_vldata_strong'_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong' min max l s) h input pos
))
(ensures (
let sz = l in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong' min max l s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong' min max l s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong' min max l s) h input pos
))))
= valid_facts (parse_bounded_vldata_strong' min max l s) h input pos;
valid_facts (parse_bounded_vldata' min max l p) h input pos;
valid_bounded_vldata'_elim h min max l p input pos
let valid_bounded_vldata_strong_elim
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max s) h input pos
))
(ensures (
let sz = log256' max in
valid (parse_bounded_integer sz) h input pos /\ (
let len_payload = contents (parse_bounded_integer sz) h input pos in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
sz + U32.v len_payload == content_length (parse_bounded_vldata_strong min max s) h input pos /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos (parse_bounded_vldata_strong min max s) h input pos (pos_payload `U32.add` len_payload) /\
valid_exact p h input pos_payload (pos_payload `U32.add` len_payload) /\
contents_exact p h input pos_payload (pos_payload `U32.add` len_payload) == contents (parse_bounded_vldata_strong min max s) h input pos
))))
= valid_bounded_vldata_strong'_elim h min max (log256' max) s input pos
let valid_bounded_vldata_strong_intro
(h: HS.mem)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
min <= U32.v len_payload /\ U32.v len_payload <= max /\
valid (parse_bounded_integer sz) h input pos /\
contents (parse_bounded_integer sz) h input pos == len_payload
))))
(ensures (
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h input pos x pos'
))
= valid_facts (parse_bounded_vldata_strong min max s) h input pos;
valid_facts (parse_bounded_vldata min max p) h input pos;
valid_bounded_vldata_intro h min max p input pos pos';
valid_exact_serialize s h input (pos `U32.add` U32.uint_to_t (log256' max)) pos'
inline_for_extraction
let finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos' | false | false | LowParse.Low.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_bounded_vldata_strong_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_exact p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vldata_strong min max s) h' input pos x pos')) | [] | LowParse.Low.VLData.finalize_bounded_vldata_strong_exact | {
"file_name": "src/lowparse/LowParse.Low.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 62,
"end_line": 525,
"start_col": 2,
"start_line": 513
} |
Prims.Tot | val clens_vlarray_nth (t: Type) (min max i: nat) : Tot (clens (vlarray t min max) t) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
} | val clens_vlarray_nth (t: Type) (min max i: nat) : Tot (clens (vlarray t min max) t)
let clens_vlarray_nth (t: Type) (min max i: nat) : Tot (clens (vlarray t min max) t) = | false | null | false | {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i)
} | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Low.Base.Spec.Mkclens",
"LowParse.Spec.Array.vlarray",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.List.Tot.Base.length",
"FStar.List.Tot.Base.index",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_vlarray_nth (t: Type) (min max i: nat) : Tot (clens (vlarray t min max) t) | [] | LowParse.Low.Array.clens_vlarray_nth | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t: Type -> min: Prims.nat -> max: Prims.nat -> i: Prims.nat
-> LowParse.Low.Base.Spec.clens (LowParse.Spec.Array.vlarray t min max) t | {
"end_col": 58,
"end_line": 487,
"start_col": 2,
"start_line": 486
} |
Prims.GTot | val array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: GTot (nat) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) | val array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: GTot (nat)
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: GTot (nat) = | false | null | false | if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"sometrivial"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_LessThan",
"LowParse.Bytes.bytes",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes) | false | false | LowParse.Low.Array.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: GTot (nat) | [] | LowParse.Low.Array.array_nth_ghost'' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count } ->
input: LowParse.Bytes.bytes
-> Prims.GTot Prims.nat | {
"end_col": 10,
"end_line": 79,
"start_col": 2,
"start_line": 77
} |
Prims.GTot | val vlarray_nth_ghost''
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: GTot (nat) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) | val vlarray_nth_ghost''
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: GTot (nat)
let vlarray_nth_ghost''
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: GTot (nat) = | false | null | false | if
(log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <=
Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"sometrivial"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Bytes.bytes",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"LowParse.Spec.BoundedInt.log256'",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"LowParse.Math.mult_nat"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_ghost''
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: GTot (nat) | [] | LowParse.Low.Array.vlarray_nth_ghost'' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
input: LowParse.Bytes.bytes
-> Prims.GTot Prims.nat | {
"end_col": 10,
"end_line": 566,
"start_col": 2,
"start_line": 564
} |
Prims.Tot | val clens_array_nth (t: Type) (elem_count: nat) (i: nat{i < elem_count})
: Tot (clens (array t elem_count) t) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
} | val clens_array_nth (t: Type) (elem_count: nat) (i: nat{i < elem_count})
: Tot (clens (array t elem_count) t)
let clens_array_nth (t: Type) (elem_count: nat) (i: nat{i < elem_count})
: Tot (clens (array t elem_count) t) = | false | null | false | { clens_cond = (fun _ -> True); clens_get = (fun (l: array t elem_count) -> L.index l i) } | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"LowParse.Low.Base.Spec.Mkclens",
"LowParse.Spec.Array.array",
"Prims.l_True",
"FStar.List.Tot.Base.index",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_array_nth (t: Type) (elem_count: nat) (i: nat{i < elem_count})
: Tot (clens (array t elem_count) t) | [] | LowParse.Low.Array.clens_array_nth | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t: Type -> elem_count: Prims.nat -> i: Prims.nat{i < elem_count}
-> LowParse.Low.Base.Spec.clens (LowParse.Spec.Array.array t elem_count) t | {
"end_col": 59,
"end_line": 56,
"start_col": 2,
"start_line": 55
} |
Prims.Tot | val vlarray_nth_compute
(a: nat)
(b c: U32.t)
(bound:
Ghost.erased nat
{ a + ((U32.v b) `Prims.op_Multiply` (U32.v c)) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296 })
: Tot (z: U32.t{U32.v z == a + ((U32.v b) `Prims.op_Multiply` (U32.v c))}) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c) | val vlarray_nth_compute
(a: nat)
(b c: U32.t)
(bound:
Ghost.erased nat
{ a + ((U32.v b) `Prims.op_Multiply` (U32.v c)) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296 })
: Tot (z: U32.t{U32.v z == a + ((U32.v b) `Prims.op_Multiply` (U32.v c))})
let vlarray_nth_compute
(a: nat)
(b c: U32.t)
(bound:
Ghost.erased nat
{ a + ((U32.v b) `Prims.op_Multiply` (U32.v c)) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296 })
: Tot (z: U32.t{U32.v z == a + ((U32.v b) `Prims.op_Multiply` (U32.v c))}) = | false | null | false | FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro ((U32.v b) `Prims.op_Multiply` (U32.v c));
(U32.uint_to_t a) `U32.add` (b `U32.mul` c) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"FStar.UInt32.t",
"FStar.Ghost.erased",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.op_Multiply",
"FStar.UInt32.v",
"FStar.Ghost.reveal",
"Prims.op_LessThan",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.mul",
"Prims.unit",
"LowParse.Low.Array.uint32_size_intro",
"FStar.Math.Lemmas.nat_times_nat_is_nat",
"Prims.eq2",
"Prims.int"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_compute
(a: nat)
(b c: U32.t)
(bound:
Ghost.erased nat
{ a + ((U32.v b) `Prims.op_Multiply` (U32.v c)) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296 })
: Tot (z: U32.t{U32.v z == a + ((U32.v b) `Prims.op_Multiply` (U32.v c))}) | [] | LowParse.Low.Array.vlarray_nth_compute | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
a: Prims.nat ->
b: FStar.UInt32.t ->
c: FStar.UInt32.t ->
bound:
FStar.Ghost.erased Prims.nat
{ a + FStar.UInt32.v b * FStar.UInt32.v c <= FStar.Ghost.reveal bound /\
FStar.Ghost.reveal bound < 4294967296 }
-> z: FStar.UInt32.t{FStar.UInt32.v z == a + FStar.UInt32.v b * FStar.UInt32.v c} | {
"end_col": 43,
"end_line": 589,
"start_col": 2,
"start_line": 587
} |
FStar.Pervasives.Lemma | val array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input | val array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input)) = | false | null | true | reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_LessThan",
"LowParse.Bytes.bytes",
"FStar.Classical.move_requires",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Array.clens_array_nth",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Low.Array.array_nth_ghost''",
"LowParse.Low.Array.array_nth_ghost_correct'",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input)) | [] | LowParse.Low.Array.array_nth_ghost_correct | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count } ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.gaccessor_post' (LowParse.Spec.Array.parse_array s
array_byte_size
elem_count)
p
(LowParse.Low.Array.clens_array_nth t elem_count i)
input
(LowParse.Low.Array.array_nth_ghost'' s array_byte_size elem_count i input)) | {
"end_col": 89,
"end_line": 127,
"start_col": 2,
"start_line": 126
} |
Prims.Tot | val array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input | val array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i)) = | false | null | false | fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_LessThan",
"LowParse.Bytes.bytes",
"LowParse.Low.Array.array_nth_ghost''",
"Prims.unit",
"LowParse.Low.Array.array_nth_ghost_correct",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Array.clens_array_nth"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i)) | [] | LowParse.Low.Array.array_nth_ghost' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count }
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Array.parse_array s array_byte_size elem_count
)
p
(LowParse.Low.Array.clens_array_nth t elem_count i) | {
"end_col": 58,
"end_line": 146,
"start_col": 2,
"start_line": 144
} |
Prims.Tot | val validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array s array_byte_size elem_count)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u | val validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array s array_byte_size elem_count))
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array s array_byte_size elem_count)) = | false | null | false | if k.parser_kind_metadata = Some ParserKindMetadataTotal
then
validate_total_constant_size (parse_array s array_byte_size elem_count)
(FStar.Int.Cast.uint32_to_uint64 array_byte_size32)
()
else validate_array' s v array_byte_size array_byte_size32 elem_count u | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.validator",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserKindMetadataTotal",
"LowParse.Low.Base.validate_total_constant_size",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array",
"FStar.Int.Cast.uint32_to_uint64",
"LowParse.Low.Array.validate_array'"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array s array_byte_size elem_count)) | [] | LowParse.Low.Array.validate_array | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
v: LowParse.Low.Base.validator p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u133:
u134:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size }
-> LowParse.Low.Base.validator (LowParse.Spec.Array.parse_array s array_byte_size elem_count) | {
"end_col": 73,
"end_line": 374,
"start_col": 2,
"start_line": 372
} |
Prims.Tot | val jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (jumper (parse_array s array_byte_size elem_count)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 () | val jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (jumper (parse_array s array_byte_size elem_count))
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (jumper (parse_array s array_byte_size elem_count)) = | false | null | false | jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 () | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"LowParse.Low.Base.jump_constant_size",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Base.jumper"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (jumper (parse_array s array_byte_size elem_count)) | [] | LowParse.Low.Array.jump_array | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u140:
u141:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size }
-> LowParse.Low.Base.jumper (LowParse.Spec.Array.parse_array s array_byte_size elem_count) | {
"end_col": 84,
"end_line": 390,
"start_col": 2,
"start_line": 390
} |
Prims.Tot | val validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array' s array_byte_size elem_count)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
() | val validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array' s array_byte_size elem_count))
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array' s array_byte_size elem_count)) = | false | null | false | validate_synth (validate_fldata_strong (serialize_list _ s)
(validate_list v ())
array_byte_size
array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
() | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.validator",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"LowParse.Low.Combinators.validate_synth",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.array",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Low.FLData.validate_fldata_strong",
"LowParse.Low.List.validate_list",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.parse_array'"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
: Tot (validator (parse_array' s array_byte_size elem_count)) | [] | LowParse.Low.Array.validate_array' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
v: LowParse.Low.Base.validator p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u124:
u125:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size }
-> LowParse.Low.Base.validator (LowParse.Spec.Array.parse_array' s array_byte_size elem_count) | {
"end_col": 6,
"end_line": 355,
"start_col": 2,
"start_line": 352
} |
Prims.Tot | val array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i | val array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i)) = | false | null | false | reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size)
(parse_array s array_byte_size elem_count);
assert (forall x.
gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==>
(i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
(array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_LessThan",
"LowParse.Low.Array.array_nth_ghost'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Array.clens_array_nth",
"Prims._assert",
"Prims.l_Forall",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"Prims.l_imp",
"LowParse.Low.Base.Spec.gaccessor_pre",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"LowParse.Spec.Array.parse_array_kind'",
"FStar.Math.Lemmas.lemma_mult_le_right",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Pervasives.reveal_opaque",
"LowParse.Bytes.bytes",
"LowParse.Low.Array.array_nth_ghost''",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i)) | [] | LowParse.Low.Array.array_nth_ghost | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count }
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Array.parse_array s array_byte_size elem_count)
p
(LowParse.Low.Array.clens_array_nth t elem_count i) | {
"end_col": 49,
"end_line": 171,
"start_col": 2,
"start_line": 163
} |
FStar.Pervasives.Lemma | val valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos | val valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'))
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos')) = | false | null | true | valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos';
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.parse_array'",
"LowParse.Low.Array.valid_list_valid_array'",
"LowParse.Low.Base.Spec.valid_list",
"FStar.List.Tot.Base.length",
"LowParse.Low.Base.Spec.contents_list",
"Prims.op_Subtraction",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"Prims.list",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos' | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos')) | [] | LowParse.Low.Array.valid_list_valid_array | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u88:
u99:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size } ->
h: FStar.Monotonic.HyperStack.mem ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid_list p h input pos pos' /\
(FStar.List.Tot.Base.length (LowParse.Low.Base.Spec.contents_list p h input pos pos') ==
elem_count \/ FStar.UInt32.v pos' - FStar.UInt32.v pos == array_byte_size))
(ensures
(let x = LowParse.Low.Base.Spec.contents_list p h input pos pos' in
FStar.List.Tot.Base.length x == elem_count /\
FStar.UInt32.v pos' - FStar.UInt32.v pos == array_byte_size /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Array.parse_array s
array_byte_size
elem_count)
h
input
pos
x
pos')) | {
"end_col": 68,
"end_line": 267,
"start_col": 2,
"start_line": 265
} |
FStar.Pervasives.Lemma | val valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos | val valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x))
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x)) = | false | null | true | valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Array.valid_array_valid_list'",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.parse_array'",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.op_Subtraction",
"LowParse.Low.Base.Spec.valid_list",
"Prims.list",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
)) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x)) | [] | LowParse.Low.Array.valid_array_valid_list | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u114:
u126:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size } ->
h: FStar.Monotonic.HyperStack.mem ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.Array.parse_array s array_byte_size elem_count)
h
input
pos)
(ensures
(let pos' =
LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.Array.parse_array s
array_byte_size
elem_count)
h
input
pos
in
let x =
LowParse.Low.Base.Spec.contents (LowParse.Spec.Array.parse_array s
array_byte_size
elem_count)
h
input
pos
in
FStar.UInt32.v pos' - FStar.UInt32.v pos == array_byte_size /\
LowParse.Low.Base.Spec.valid_list p h input pos pos' /\
LowParse.Low.Base.Spec.contents_list p h input pos pos' == x)) | {
"end_col": 86,
"end_line": 335,
"start_col": 2,
"start_line": 333
} |
Prims.Tot | val jump_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max})
: Tot
(jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
() | val jump_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max})
: Tot
(jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
))
let jump_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max})
: Tot
(jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
)) = | false | null | false | vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth (jump_bounded_vldata_strong array_byte_size_min
array_byte_size_max
(serialize_list _ s)
())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
() | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"FStar.UInt32.t",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Low.Combinators.jump_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.VLData.jump_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"LowParse.Low.Base.jumper",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.parse_vlarray"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } ) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max})
: Tot
(jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u
)) | [] | LowParse.Low.Array.jump_vlarray | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u162:
u164:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
sz32:
FStar.UInt32.t{FStar.UInt32.v sz32 == LowParse.Spec.BoundedInt.log256' array_byte_size_max}
-> LowParse.Low.Base.jumper (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u162) | {
"end_col": 6,
"end_line": 433,
"start_col": 2,
"start_line": 429
} |
Prims.Tot | val validate_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296})
: Tot
(validator (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
() | val validate_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296})
: Tot
(validator (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u))
let validate_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296})
: Tot
(validator (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)) = | false | null | false | vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth (validate_bounded_vldata_strong array_byte_size_min
array_byte_size_max
(serialize_list _ s)
(validate_list v ())
())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
() | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.validator",
"Prims.unit",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Spec.BoundedInt.log256'",
"Prims.op_LessThan",
"LowParse.Low.Combinators.validate_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.VLData.validate_bounded_vldata_strong",
"LowParse.Low.List.validate_list",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.parse_vlarray"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } ) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min elem_count_max: nat)
(u:
unit
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(sz32: U32.t{U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296})
: Tot
(validator (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u)) | [] | LowParse.Low.Array.validate_vlarray | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
v: LowParse.Low.Base.validator p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
u153:
u155:
Prims.unit
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
sz32:
FStar.UInt32.t
{ FStar.UInt32.v sz32 == LowParse.Spec.BoundedInt.log256' array_byte_size_max /\
array_byte_size_max < 4294967296 }
-> LowParse.Low.Base.validator (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
u153) | {
"end_col": 6,
"end_line": 412,
"start_col": 2,
"start_line": 408
} |
FStar.Pervasives.Lemma | val valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos | val valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'))
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos')) = | false | null | true | valid_list_valid_exact_list p h input pos pos';
valid_exact_equiv (parse_list p) h input pos pos';
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p
(Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h
(parse_fldata_strong (serialize_list _ s) array_byte_size)
(fldata_to_array s array_byte_size elem_count ())
input
pos | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Combinators.valid_synth",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.array",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.Base.Spec.contents_exact_eq",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"FStar.Seq.Base.slice",
"LowParse.Slice.bytes_of_slice_from",
"FStar.UInt32.sub",
"LowParse.Low.Base.Spec.valid_exact_equiv",
"LowParse.Low.List.valid_list_valid_exact_list",
"LowParse.Low.Base.Spec.valid_list",
"FStar.List.Tot.Base.length",
"LowParse.Low.Base.Spec.contents_list",
"Prims.op_Subtraction",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.parse_array'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos' | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma
(requires
(valid_list p h input pos pos' /\
(L.length (contents_list p h input pos pos') == elem_count \/
U32.v pos' - U32.v pos == array_byte_size)))
(ensures
(let x = contents_list p h input pos pos' in
L.length x == elem_count /\ U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos')) | [] | LowParse.Low.Array.valid_list_valid_array' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u74:
u85:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size } ->
h: FStar.Monotonic.HyperStack.mem ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid_list p h input pos pos' /\
(FStar.List.Tot.Base.length (LowParse.Low.Base.Spec.contents_list p h input pos pos') ==
elem_count \/ FStar.UInt32.v pos' - FStar.UInt32.v pos == array_byte_size))
(ensures
(let x = LowParse.Low.Base.Spec.contents_list p h input pos pos' in
FStar.List.Tot.Base.length x == elem_count /\
FStar.UInt32.v pos' - FStar.UInt32.v pos == array_byte_size /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Array.parse_array' s
array_byte_size
elem_count)
h
input
pos
x
pos')) | {
"end_col": 134,
"end_line": 238,
"start_col": 2,
"start_line": 232
} |
FStar.Pervasives.Lemma | val valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array' s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos' | val valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array' s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x))
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array' s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x)) = | false | null | true | let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h
(parse_fldata_strong (serialize_list _ s) array_byte_size)
(fldata_to_array s array_byte_size elem_count ())
input
pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos';
contents_exact_eq (parse_list p) h input pos pos';
valid_exact_list_valid_list p h input pos pos' | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.List.valid_exact_list_valid_list",
"LowParse.Low.Base.Spec.contents_exact_eq",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Low.Base.Spec.valid_exact_equiv",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Low.Combinators.valid_synth",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Low.Base.Spec.contents",
"LowParse.Spec.Array.parse_array_kind'",
"LowParse.Spec.Array.parse_array'",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.op_Subtraction",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.contents_list",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u:
unit
{ fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size })
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid (parse_array' s array_byte_size elem_count) h input pos))
(ensures
(let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\ valid_list p h input pos pos' /\
contents_list p h input pos pos' == x)) | [] | LowParse.Low.Array.valid_array_valid_list' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
array_byte_size32: FStar.UInt32.t ->
elem_count: Prims.nat ->
u101:
u113:
Prims.unit
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
FStar.UInt32.v array_byte_size32 == array_byte_size } ->
h: FStar.Monotonic.HyperStack.mem ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.Array.parse_array' s array_byte_size elem_count)
h
input
pos)
(ensures
(let pos' =
LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.Array.parse_array' s
array_byte_size
elem_count)
h
input
pos
in
let x =
LowParse.Low.Base.Spec.contents (LowParse.Spec.Array.parse_array' s
array_byte_size
elem_count)
h
input
pos
in
FStar.UInt32.v pos' - FStar.UInt32.v pos == array_byte_size /\
LowParse.Low.Base.Spec.valid_list p h input pos pos' /\
LowParse.Low.Base.Spec.contents_list p h input pos pos' == x)) | {
"end_col": 50,
"end_line": 303,
"start_col": 1,
"start_line": 296
} |
Prims.Tot | val array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
U32.t
{ fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ U32.v i < elem_count })
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i))) | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low) | val array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
U32.t
{ fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ U32.v i < elem_count })
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
U32.t
{ fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ U32.v i < elem_count })
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i))) = | false | null | false | fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@@ inline_let ]let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size))
(fldata_to_array s array_byte_size elem_count ())
(bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p
(Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size)
(U32.v i)
in
pos `U32.add` (i `U32.mul` (U32.uint_to_t k.parser_kind_low)) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.add",
"FStar.UInt32.mul",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"LowParse.Low.Array.list_nth_constant_size_parser_correct",
"FStar.Seq.Base.slice",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.array",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Spec.Array.fldata_to_array_inj",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Array.clens_array_nth",
"LowParse.Low.Array.array_nth_ghost",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Pervasives.reveal_opaque",
"LowParse.Bytes.bytes",
"LowParse.Low.Array.array_nth_ghost''",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Low.Array.array_nth_ghost'",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
U32.t
{ fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ U32.v i < elem_count })
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i))) | [] | LowParse.Low.Array.array_nth | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
i:
FStar.UInt32.t
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ FStar.UInt32.v i < elem_count }
-> LowParse.Low.Base.accessor (LowParse.Low.Array.array_nth_ghost s
array_byte_size
elem_count
(FStar.UInt32.v i)) | {
"end_col": 61,
"end_line": 203,
"start_col": 2,
"start_line": 190
} |
Prims.Pure | val vlarray_nth_body
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: Ghost.erased bytes)
: Pure U32.t
(requires
(Seq.length (Ghost.reveal input) < 4294967296 /\
gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max (U32.v i))
(Ghost.reveal input)))
(ensures
(fun y ->
U32.v y ==
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i)
(Ghost.reveal input)))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input))) | val vlarray_nth_body
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: Ghost.erased bytes)
: Pure U32.t
(requires
(Seq.length (Ghost.reveal input) < 4294967296 /\
gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max (U32.v i))
(Ghost.reveal input)))
(ensures
(fun y ->
U32.v y ==
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i)
(Ghost.reveal input))))
let vlarray_nth_body
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: Ghost.erased bytes)
: Pure U32.t
(requires
(Seq.length (Ghost.reveal input) < 4294967296 /\
gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max (U32.v i))
(Ghost.reveal input)))
(ensures
(fun y ->
U32.v y ==
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i)
(Ghost.reveal input)))) = | false | null | false | reveal_opaque (`%vlarray_nth_ghost'')
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i)
(Ghost.reveal input));
[@@ inline_let ]let _:squash ((log256' array_byte_size_max +
((U32.v i) `Prims.op_Multiply` k.parser_kind_low) +
k.parser_kind_low) <=
Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
()
(Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq =
Seq.slice (Ghost.reveal input)
(log256' array_byte_size_max)
(log256' array_byte_size_max + U32.v len)
in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max)
i
(U32.uint_to_t k.parser_kind_low)
(Ghost.hide (Seq.length (Ghost.reveal input))) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"FStar.Ghost.erased",
"LowParse.Bytes.bytes",
"LowParse.Low.Array.vlarray_nth_compute",
"LowParse.Spec.BoundedInt.log256'",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Ghost.hide",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.Ghost.reveal",
"Prims.squash",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.op_Multiply",
"FStar.UInt32.v",
"LowParse.Low.Array.list_nth_constant_size_parser_correct",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"LowParse.Spec.Base.consumed_length",
"FStar.Pervasives.Native.snd",
"LowParse.Spec.BoundedInt.bounded_integer",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parse",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.unit",
"LowParse.Spec.Array.parse_vlarray_eq_some",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Array.vlarray_nth_ghost''",
"Prims.l_and",
"Prims.op_LessThan",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input)))) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_body
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: Ghost.erased bytes)
: Pure U32.t
(requires
(Seq.length (Ghost.reveal input) < 4294967296 /\
gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max (U32.v i))
(Ghost.reveal input)))
(ensures
(fun y ->
U32.v y ==
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i)
(Ghost.reveal input)))) | [] | LowParse.Low.Array.vlarray_nth_body | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
FStar.UInt32.t
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
input: FStar.Ghost.erased LowParse.Bytes.bytes
-> Prims.Pure FStar.UInt32.t | {
"end_col": 139,
"end_line": 622,
"start_col": 6,
"start_line": 611
} |
FStar.Pervasives.Lemma | val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end | val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i = | false | null | true | parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else
(M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma",
""
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Bytes.bytes",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"LowParse.Low.Array.list_nth_constant_size_parser_correct",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"Prims.op_Subtraction",
"Prims.unit",
"LowParse.Math.mult_decomp",
"LowParse.Spec.List.parse_list_eq",
"LowParse.Spec.Base.parser_kind_prop_equiv"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i) | [
"recursion"
] | LowParse.Low.Array.list_nth_constant_size_parser_correct | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: LowParse.Spec.Base.parser k t -> b: LowParse.Bytes.bytes -> i: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_high k ==
FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\
Some? (LowParse.Spec.Base.parse (LowParse.Spec.List.parse_list p) b) /\
(let _ = LowParse.Spec.Base.parse (LowParse.Spec.List.parse_list p) b in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ l _) = _ in
i < FStar.List.Tot.Base.length l)
<:
Prims.logical))
(ensures
(let j = i * Mkparser_kind'?.parser_kind_low k in
0 <= j /\ j + Mkparser_kind'?.parser_kind_low k <= FStar.Seq.Base.length b /\
(let b' = FStar.Seq.Base.slice b j (FStar.Seq.Base.length b) in
Some? (LowParse.Spec.Base.parse p b') /\
(let _ = LowParse.Spec.Base.parse (LowParse.Spec.List.parse_list p) b in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ l _) =
_
in
let _ = LowParse.Spec.Base.parse p b' in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x _) =
_
in
x == FStar.List.Tot.Base.index l i)
<:
Prims.logical)
<:
Prims.logical))))
(decreases i) | {
"end_col": 5,
"end_line": 47,
"start_col": 2,
"start_line": 40
} |
FStar.HyperStack.ST.Stack | val vlarray_list_length
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
valid (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos))
(ensures
(fun h res h' ->
let x =
(contents (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos)
in
let pos' =
get_valid_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos
in
B.modifies B.loc_none h h' /\ U32.v res == L.length x /\
U32.v pos' ==
U32.v pos + (log256' array_byte_size_max) +
((U32.v res) `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' /\
contents_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' ==
x)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow | val vlarray_list_length
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
valid (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos))
(ensures
(fun h res h' ->
let x =
(contents (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos)
in
let pos' =
get_valid_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos
in
B.modifies B.loc_none h h' /\ U32.v res == L.length x /\
U32.v pos' ==
U32.v pos + (log256' array_byte_size_max) +
((U32.v res) `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' /\
contents_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' ==
x))
let vlarray_list_length
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
valid (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos))
(ensures
(fun h res h' ->
let x =
(contents (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos)
in
let pos' =
get_valid_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos
in
B.modifies B.loc_none h h' /\ U32.v res == L.length x /\
U32.v pos' ==
U32.v pos + (log256' array_byte_size_max) +
((U32.v res) `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' /\
contents_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' ==
x)) = | true | null | false | let h = HST.get () in
[@@ inline_let ]let _:unit =
let l =
contents (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos
in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq (parse_bounded_vldata_strong array_byte_size_min
array_byte_size_max
(serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max)
(in_bounds array_byte_size_min array_byte_size_max)
(parse_list p)
sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p
(Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max)) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@@ inline_let ]let klow:U32.t = U32.uint_to_t k.parser_kind_low in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.div",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Low.BoundedInt.read_bounded_integer",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"LowParse.Spec.Base.consumed_length",
"LowParse.Low.List.valid_exact_list_valid_list",
"LowParse.Low.Base.Spec.contents_exact_eq",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Low.Base.Spec.valid_exact_equiv",
"FStar.UInt32.add",
"FStar.Math.Lemmas.multiple_division_lemma",
"FStar.List.Tot.Base.length",
"LowParse.Spec.List.list_length_constant_size_parser_correct",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Spec.BoundedInt.in_bounds",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"LowParse.Spec.Array.vldata_to_vlarray_inj",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Bytes.bytes",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.contents",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Low.Base.Spec.valid",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Mul.op_Star",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.Base.Spec.get_valid_pos"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_list_length
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
valid (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos))
(ensures
(fun h res h' ->
let x =
(contents (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos)
in
let pos' =
get_valid_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h
sl
pos
in
B.modifies B.loc_none h h' /\ U32.v res == L.length x /\
U32.v pos' ==
U32.v pos + (log256' array_byte_size_max) +
((U32.v res) `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' /\
contents_list p h sl (pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max))) pos' ==
x)) | [] | LowParse.Low.Array.vlarray_list_length | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | {
"end_col": 21,
"end_line": 545,
"start_col": 1,
"start_line": 517
} |
FStar.HyperStack.ST.Stack | val finalize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
(let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\
(let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\
(let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/
(elem_count_min <= count /\ count <= elem_count_max)))))))
(ensures
(fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\ elem_count_min <= L.length l /\
L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h'
sl
pos
l
pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos | val finalize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
(let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\
(let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\
(let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/
(elem_count_min <= count /\ count <= elem_count_max)))))))
(ensures
(fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\ elem_count_min <= L.length l /\
L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h'
sl
pos
l
pos'))
let finalize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
(let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\
(let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\
(let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/
(elem_count_min <= count /\ count <= elem_count_max)))))))
(ensures
(fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\ elem_count_min <= L.length l /\
L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h'
sl
pos
l
pos')) = | true | null | false | let h = HST.get () in
let pos1 = pos `U32.add` (U32.uint_to_t (log256' array_byte_size_max)) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _:squash (let count = L.length (Ghost.reveal l) in
elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos';
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max)
(Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min
array_byte_size_max
(serialize_list _ s)
sl
pos
pos';
let h = HST.get () in
valid_synth h
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sl
pos | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Combinators.valid_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Spec.Array.vldata_to_vlarray",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.VLData.finalize_bounded_vldata_strong_exact",
"LowParse.Spec.Array.vlarray_to_vldata_correct",
"FStar.Ghost.reveal",
"Prims.squash",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length",
"FStar.Classical.move_requires",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Spec.Array.vlarray_pred",
"LowParse.Spec.Array.vldata_to_vlarray_correct",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"FStar.Ghost.erased",
"FStar.Ghost.hide",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.List.valid_list_valid_exact_list",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"Prims.op_LessThan",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.UInt32.v",
"Prims.l_or",
"Prims.int",
"Prims.op_Subtraction",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.parse_vlarray"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos' | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_vlarray
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true /\
(let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\
(let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\
(let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/
(elem_count_min <= count /\ count <= elem_count_max)))))))
(ensures
(fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\ elem_count_min <= L.length l /\
L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
h'
sl
pos
l
pos')) | [] | LowParse.Low.Array.finalize_vlarray | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 209,
"end_line": 478,
"start_col": 1,
"start_line": 467
} |
FStar.Pervasives.Lemma | val array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input))
(ensures
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input)) | val array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input))
(ensures
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input)))
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input))
(ensures
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input))) = | false | null | true | reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size)
(fldata_to_array s array_byte_size elem_count ())
input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p
(Seq.slice input0 off (Seq.length input0))
(Seq.slice input off (Seq.length input)) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.fldata_array_precond",
"Prims.b2t",
"Prims.op_LessThan",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_strong_prefix",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"FStar.Seq.Base.length",
"Prims.int",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.unit",
"LowParse.Low.Array.list_nth_constant_size_parser_correct",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.FLData.parse_fldata_strong",
"FStar.Seq.Base.seq",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.Array.array",
"LowParse.Spec.Array.fldata_to_array",
"LowParse.Spec.Array.fldata_to_array_inj",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Array.array_nth_ghost''",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Array.parse_array_kind",
"LowParse.Spec.Array.parse_array",
"LowParse.Low.Array.clens_array_nth",
"Prims.squash",
"LowParse.Low.Base.Spec.gaccessor_post'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input)) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size elem_count: nat)
(i:
nat
{ fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input))
(ensures
(gaccessor_post' (parse_array s array_byte_size elem_count)
p
(clens_array_nth t elem_count i)
input
(array_nth_ghost'' s array_byte_size elem_count i input))) | [] | LowParse.Low.Array.array_nth_ghost_correct' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.Base.serializer p ->
array_byte_size: Prims.nat ->
elem_count: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\ elem_count < 4294967296 /\ i < elem_count } ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Array.parse_array s
array_byte_size
elem_count)
p
(LowParse.Low.Array.clens_array_nth t elem_count i)
input)
(ensures
LowParse.Low.Base.Spec.gaccessor_post' (LowParse.Spec.Array.parse_array s
array_byte_size
elem_count)
p
(LowParse.Low.Array.clens_array_nth t elem_count i)
input
(LowParse.Low.Array.array_nth_ghost'' s array_byte_size elem_count i input)) | {
"end_col": 107,
"end_line": 108,
"start_col": 2,
"start_line": 100
} |
Prims.Tot | val vlarray_nth_ghost'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input | val vlarray_nth_ghost'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i))
let vlarray_nth_ghost'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)) = | false | null | false | fun input ->
reveal_opaque (`%vlarray_nth_ghost'')
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input);
vlarray_nth_ghost_correct array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input;
vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Bytes.bytes",
"LowParse.Low.Array.vlarray_nth_ghost''",
"Prims.unit",
"LowParse.Low.Array.vlarray_nth_ghost_correct",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_ghost'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)) | [] | LowParse.Low.Array.vlarray_nth_ghost' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true }
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(LowParse.Low.Array.clens_vlarray_nth t elem_count_min elem_count_max i) | {
"end_col": 101,
"end_line": 693,
"start_col": 2,
"start_line": 690
} |
FStar.Pervasives.Lemma | val vlarray_nth_ghost_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input | val vlarray_nth_ghost_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input))
let vlarray_nth_ghost_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)) = | false | null | true | reveal_opaque (`%vlarray_nth_ghost'')
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i)
input | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Bytes.bytes",
"FStar.Classical.move_requires",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Low.Array.vlarray_nth_ghost''",
"LowParse.Low.Array.vlarray_nth_ghost_correct'",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_ghost_correct
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)) | [] | LowParse.Low.Array.vlarray_nth_ghost_correct | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.gaccessor_post' (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(LowParse.Low.Array.clens_vlarray_nth t elem_count_min elem_count_max i)
input
(LowParse.Low.Array.vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)) | {
"end_col": 134,
"end_line": 674,
"start_col": 2,
"start_line": 673
} |
Prims.Tot | val vlarray_nth
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(accessor (vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (accessor (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i)))
= reveal_opaque (`%vlarray_nth_ghost) (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
make_accessor_from_pure
(vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i))
(fun input ->
vlarray_nth_body array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
) | val vlarray_nth
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(accessor (vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i)))
let vlarray_nth
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(accessor (vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i))) = | false | null | false | reveal_opaque (`%vlarray_nth_ghost)
(vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i));
reveal_opaque (`%vlarray_nth_ghost')
(vlarray_nth_ghost' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i));
make_accessor_from_pure (vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i))
(fun input ->
vlarray_nth_body array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Low.Base.make_accessor_from_pure",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth",
"FStar.UInt32.v",
"LowParse.Low.Array.vlarray_nth_ghost",
"FStar.Ghost.erased",
"LowParse.Bytes.bytes",
"LowParse.Low.Array.vlarray_nth_body",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Low.Array.vlarray_nth_ghost'",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x
))
= parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i
[@"opaque_to_smt"]
let vlarray_nth_ghost
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
Classical.forall_intro (Classical.move_requires (vlarray_nth_bound array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i));
gaccessor_prop_equiv (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i
inline_for_extraction
let vlarray_nth
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
U32.t
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(accessor (vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(U32.v i))) | [] | LowParse.Low.Array.vlarray_nth | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
FStar.UInt32.t
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true }
-> LowParse.Low.Base.accessor (LowParse.Low.Array.vlarray_nth_ghost array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
(FStar.UInt32.v i)) | {
"end_col": 5,
"end_line": 762,
"start_col": 2,
"start_line": 756
} |
Prims.Tot | val vlarray_nth_ghost
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_ghost
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
Classical.forall_intro (Classical.move_requires (vlarray_nth_bound array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i));
gaccessor_prop_equiv (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i | val vlarray_nth_ghost
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i))
let vlarray_nth_ghost
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)) = | false | null | false | reveal_opaque (`%vlarray_nth_ghost')
(vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
reveal_opaque (`%vlarray_nth_ghost'')
(vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
Classical.forall_intro (Classical.move_requires (vlarray_nth_bound array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i));
gaccessor_prop_equiv (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
(vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"total"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Low.Array.vlarray_nth_ghost'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth",
"FStar.Classical.forall_intro",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"LowParse.Low.Base.Spec.gaccessor_pre",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"LowParse.Spec.BoundedInt.log256'",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.Classical.move_requires",
"LowParse.Low.Array.vlarray_nth_bound",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Array.vlarray_nth_ghost''",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x
))
= parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i
[@"opaque_to_smt"]
let vlarray_nth_ghost
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
}) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_ghost
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
: Tot
(gaccessor (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)) | [] | LowParse.Low.Array.vlarray_nth_ghost | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true }
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(LowParse.Low.Array.clens_vlarray_nth t elem_count_min elem_count_max i) | {
"end_col": 94,
"end_line": 740,
"start_col": 2,
"start_line": 736
} |
FStar.Pervasives.Lemma | val vlarray_nth_bound
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
x))
(ensures
(log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <=
Seq.length x)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x
))
= parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i | val vlarray_nth_bound
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
x))
(ensures
(log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <=
Seq.length x))
let vlarray_nth_bound
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
x))
(ensures
(log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <=
Seq.length x)) = | false | null | true | parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Bytes.bytes",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.Base.consumed_length",
"LowParse.Low.Array.list_nth_constant_size_parser_correct",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"LowParse.Spec.Base.parse",
"LowParse.Spec.List.parse_list",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Pervasives.Native.option",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Array.parse_vlarray_eq_some",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_bound
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(x: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
x))
(ensures
(log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <=
Seq.length x)) | [] | LowParse.Low.Array.vlarray_nth_bound | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
x: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(LowParse.Low.Array.clens_vlarray_nth t elem_count_min elem_count_max i)
x)
(ensures
LowParse.Spec.BoundedInt.log256' array_byte_size_max + i * Mkparser_kind'?.parser_kind_low k +
Mkparser_kind'?.parser_kind_low k <=
FStar.Seq.Base.length x) | {
"end_col": 50,
"end_line": 720,
"start_col": 2,
"start_line": 715
} |
FStar.Pervasives.Lemma | val valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\ True)
)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True
)))
= valid_bounded_vldata_strong_elim h min max (serialize_list _ s) input pos;
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
valid_exact_list_valid_list p h input pos1 pos' | val valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\ True)
))
let valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\ True)
)) = | false | null | true | valid_bounded_vldata_strong_elim h min max (serialize_list _ s) input pos;
let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
valid_exact_list_valid_list p h input pos1 pos' | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.List.valid_exact_list_valid_list",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"Prims.unit",
"LowParse.Low.VLData.valid_bounded_vldata_strong_elim",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.Base.Spec.contents",
"Prims.l_True",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x
))
= parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i
[@"opaque_to_smt"]
let vlarray_nth_ghost
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
Classical.forall_intro (Classical.move_requires (vlarray_nth_bound array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i));
gaccessor_prop_equiv (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i
inline_for_extraction
let vlarray_nth
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (accessor (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i)))
= reveal_opaque (`%vlarray_nth_ghost) (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
make_accessor_from_pure
(vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i))
(fun input ->
vlarray_nth_body array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
)
module HS = FStar.HyperStack
let valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\ True)
)) | [] | LowParse.Low.Array.valid_bounded_vldata_strong_list_valid_list | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_low k > 0 } ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLData.parse_bounded_vldata_strong min
max
(LowParse.Spec.List.serialize_list p s))
h
input
pos)
(ensures
(let pos' =
LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.VLData.parse_bounded_vldata_strong min
max
(LowParse.Spec.List.serialize_list p s))
h
input
pos
in
FStar.UInt32.v pos + LowParse.Spec.BoundedInt.log256' max <= FStar.UInt32.v pos' /\
(let pos1 =
FStar.UInt32.add pos (FStar.UInt32.uint_to_t (LowParse.Spec.BoundedInt.log256' max))
in
LowParse.Low.Base.Spec.valid_list p h input pos1 pos' /\
LowParse.Low.Base.Spec.contents_list p h input pos1 pos' ==
LowParse.Low.Base.Spec.contents (LowParse.Spec.VLData.parse_bounded_vldata_strong min
max
(LowParse.Spec.List.serialize_list p s))
h
input
pos /\ Prims.l_True))) | {
"end_col": 49,
"end_line": 792,
"start_col": 2,
"start_line": 789
} |
FStar.HyperStack.ST.Stack | val finalize_bounded_vldata_strong_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_list p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize (serialize_list _ s)
(contents_list p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos_payload) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_list p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize (serialize_list _ s) x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max (serialize_list _ s) x /\
valid_content_pos (parse_bounded_vldata_strong min max (serialize_list _ s))
h'
input
pos
x
pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let finalize_bounded_vldata_strong_list
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_list p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize (serialize_list _ s) (contents_list p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos_payload) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_list p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize (serialize_list _ s) x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max (serialize_list _ s) x /\
valid_content_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let] let _ = valid_list_valid_exact_list p h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' in
finalize_bounded_vldata_strong_exact min max (serialize_list _ s) input pos pos' | val finalize_bounded_vldata_strong_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_list p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize (serialize_list _ s)
(contents_list p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos_payload) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_list p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize (serialize_list _ s) x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max (serialize_list _ s) x /\
valid_content_pos (parse_bounded_vldata_strong min max (serialize_list _ s))
h'
input
pos
x
pos'))
let finalize_bounded_vldata_strong_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_list p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize (serialize_list _ s)
(contents_list p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos_payload) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_list p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize (serialize_list _ s) x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max (serialize_list _ s) x /\
valid_content_pos (parse_bounded_vldata_strong min max (serialize_list _ s))
h'
input
pos
x
pos')) = | true | null | false | let h = HST.get () in
[@@ inline_let ]let _ =
valid_list_valid_exact_list p h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos'
in
finalize_bounded_vldata_strong_exact min max (serialize_list _ s) input pos pos' | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.VLData.finalize_bounded_vldata_strong_exact",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"Prims.unit",
"LowParse.Low.List.valid_list_valid_exact_list",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.log256'",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.l_or",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.contents_list",
"FStar.UInt32.sub",
"LowParse.Spec.BoundedInt.integer_size",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"Prims.eq2",
"Prims.int",
"Prims.op_Subtraction",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x
))
= parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i
[@"opaque_to_smt"]
let vlarray_nth_ghost
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
Classical.forall_intro (Classical.move_requires (vlarray_nth_bound array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i));
gaccessor_prop_equiv (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i
inline_for_extraction
let vlarray_nth
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (accessor (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i)))
= reveal_opaque (`%vlarray_nth_ghost) (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
make_accessor_from_pure
(vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i))
(fun input ->
vlarray_nth_body array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
)
module HS = FStar.HyperStack
let valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True
)))
= valid_bounded_vldata_strong_elim h min max (serialize_list _ s) input pos;
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
valid_exact_list_valid_list p h input pos1 pos'
inline_for_extraction
let bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (fun h res h' ->
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
B.modifies B.loc_none h h' /\
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
res == pos' `U32.sub` pos1 /\
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True
)))
= let h = HST.get () in
let pos' = jump_bounded_vldata_strong min max (serialize_list _ s) () input pos in
[@inline_let]
let _ =
assert (valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos pos')
in
[@inline_let] let _ = valid_bounded_vldata_strong_list_valid_list min max p s input pos h in
[@inline_let] let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
[@inline_let] let res = pos' `U32.sub` pos1 in
res
inline_for_extraction
let finalize_bounded_vldata_strong_list
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_list p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize (serialize_list _ s) (contents_list p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos_payload) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = log256' max in
let x = contents_list p h input (pos `U32.add` U32.uint_to_t sz) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` U32.uint_to_t sz)) h h' /\
Seq.length (serialize (serialize_list _ s) x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max (serialize_list _ s) x /\
valid_content_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h' input pos x pos' | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val finalize_bounded_vldata_strong_list
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = log256' max in
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_list p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize (serialize_list _ s)
(contents_list p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos_payload) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = log256' max in
let x = contents_list p h input (pos `U32.add` (U32.uint_to_t sz)) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` (U32.uint_to_t sz))) h h' /\
Seq.length (serialize (serialize_list _ s) x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max (serialize_list _ s) x /\
valid_content_pos (parse_bounded_vldata_strong min max (serialize_list _ s))
h'
input
pos
x
pos')) | [] | LowParse.Low.Array.finalize_bounded_vldata_strong_list | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 82,
"end_line": 863,
"start_col": 1,
"start_line": 861
} |
FStar.HyperStack.ST.Stack | val bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(fun h res h' ->
let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
B.modifies B.loc_none h h' /\ U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
res == pos' `U32.sub` pos1 /\ valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (fun h res h' ->
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
B.modifies B.loc_none h h' /\
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
res == pos' `U32.sub` pos1 /\
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True
)))
= let h = HST.get () in
let pos' = jump_bounded_vldata_strong min max (serialize_list _ s) () input pos in
[@inline_let]
let _ =
assert (valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos pos')
in
[@inline_let] let _ = valid_bounded_vldata_strong_list_valid_list min max p s input pos h in
[@inline_let] let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
[@inline_let] let res = pos' `U32.sub` pos1 in
res | val bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(fun h res h' ->
let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
B.modifies B.loc_none h h' /\ U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
res == pos' `U32.sub` pos1 /\ valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True)))
let bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(fun h res h' ->
let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
B.modifies B.loc_none h h' /\ U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
res == pos' `U32.sub` pos1 /\ valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True))) = | true | null | false | let h = HST.get () in
let pos' = jump_bounded_vldata_strong min max (serialize_list _ s) () input pos in
[@@ inline_let ]let _ =
assert (valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos pos')
in
[@@ inline_let ]let _ = valid_bounded_vldata_strong_list_valid_list min max p s input pos h in
[@@ inline_let ]let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
[@@ inline_let ]let res = pos' `U32.sub` pos1 in
res | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.sub",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Low.Array.valid_bounded_vldata_strong_list_valid_list",
"Prims._assert",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.List.parse_list_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"Prims.list",
"LowParse.Spec.List.parse_list",
"LowParse.Spec.List.serialize_list",
"LowParse.Spec.VLData.parse_bounded_vldata_strong",
"LowParse.Low.VLData.jump_bounded_vldata_strong",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.valid",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.Base.Spec.contents",
"Prims.l_True",
"LowParse.Low.Base.Spec.get_valid_pos"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
)
#pop-options
let vlarray_nth_ghost_correct
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
Classical.move_requires (vlarray_nth_ghost_correct' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i) input
[@"opaque_to_smt"]
let vlarray_nth_ghost'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= fun input ->
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
vlarray_nth_ghost_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input;
vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
let vlarray_nth_bound
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(x: bytes)
: Lemma
(requires (
gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) x
))
(ensures (
log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x
))
= parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () x;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) x in
let input' = Seq.slice x (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i
[@"opaque_to_smt"]
let vlarray_nth_ghost
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (gaccessor (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i))
= reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
Classical.forall_intro (Classical.move_requires (vlarray_nth_bound array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i));
gaccessor_prop_equiv (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i);
vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i
inline_for_extraction
let vlarray_nth
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
: Tot (accessor (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i)))
= reveal_opaque (`%vlarray_nth_ghost) (vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
reveal_opaque (`%vlarray_nth_ghost') (vlarray_nth_ghost' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i));
make_accessor_from_pure
(vlarray_nth_ghost array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i))
(fun input ->
vlarray_nth_body array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input
)
module HS = FStar.HyperStack
let valid_bounded_vldata_strong_list_valid_list
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True
)))
= valid_bounded_vldata_strong_elim h min max (serialize_list _ s) input pos;
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
valid_exact_list_valid_list p h input pos1 pos'
inline_for_extraction
let bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 } )
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
))
(ensures (fun h res h' ->
let pos' = get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos in
B.modifies B.loc_none h h' /\
U32.v pos + log256' max <= U32.v pos' /\ (
let pos1 = pos `U32.add` U32.uint_to_t (log256' max) in
res == pos' `U32.sub` pos1 /\
valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' == contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bounded_vldata_strong_list_payload_size
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos))
(ensures
(fun h res h' ->
let pos' =
get_valid_pos (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos
in
B.modifies B.loc_none h h' /\ U32.v pos + log256' max <= U32.v pos' /\
(let pos1 = pos `U32.add` (U32.uint_to_t (log256' max)) in
res == pos' `U32.sub` pos1 /\ valid_list p h input pos1 pos' /\
contents_list p h input pos1 pos' ==
contents (parse_bounded_vldata_strong min max (serialize_list _ s)) h input pos /\
True))) | [] | LowParse.Low.Array.bounded_vldata_strong_list_payload_size | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_low k > 0 } ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | {
"end_col": 5,
"end_line": 828,
"start_col": 1,
"start_line": 819
} |
FStar.Pervasives.Lemma | val vlarray_nth_ghost_correct'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input))
(ensures
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input))
(ensures (gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)))
= reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input);
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p (Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input')) (Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (
gaccessor_post' (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max i input)
) | val vlarray_nth_ghost_correct'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input))
(ensures
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)))
let vlarray_nth_ghost_correct'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input))
(ensures
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input))) = | false | null | true | reveal_opaque (`%vlarray_nth_ghost'')
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input);
parse_vlarray_eq_some array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
()
input;
let sz = log256' array_byte_size_max in
let Some (len, _) = parse (parse_bounded_integer sz) input in
let input' = Seq.slice input (sz) (sz + U32.v len) in
assert (Some? (parse (parse_list p) input'));
list_nth_constant_size_parser_correct p input' i;
parse_strong_prefix p
(Seq.slice input' (i `Prims.op_Multiply` k.parser_kind_low) (Seq.length input'))
(Seq.slice input (sz + (i `Prims.op_Multiply` k.parser_kind_low)) (Seq.length input));
assert (gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)) | {
"checked_file": "LowParse.Low.Array.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Array.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.List.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Array.fst"
} | [
"lemma"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"Prims.bool",
"LowParse.Spec.Array.vldata_vlarray_precond",
"LowParse.Bytes.bytes",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.Base.consumed_length",
"Prims._assert",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Spec.Array.parse_vlarray_kind",
"LowParse.Spec.Array.vlarray",
"LowParse.Spec.Array.parse_vlarray",
"LowParse.Low.Array.clens_vlarray_nth",
"LowParse.Low.Array.vlarray_nth_ghost''",
"Prims.unit",
"LowParse.Spec.Base.parse_strong_prefix",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"Prims.op_Multiply",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"LowParse.Low.Array.list_nth_constant_size_parser_correct",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"LowParse.Spec.Base.parse",
"LowParse.Spec.List.parse_list",
"FStar.Seq.Base.seq",
"FStar.UInt32.v",
"FStar.Pervasives.Native.option",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Array.parse_vlarray_eq_some",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Base.Spec.gaccessor_pre",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Array
include LowParse.Spec.Array
include LowParse.Low.List
include LowParse.Low.VLData
module L = FStar.List.Tot
module M = LowParse.Math
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
#reset-options "--z3cliopt smt.arith.nl=false --z3rlimit 16"
val list_nth_constant_size_parser_correct
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b: bytes)
(i: nat)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
Some? (parse (parse_list p) b) /\ (
let (Some (l, _)) = parse (parse_list p) b in
i < L.length l
)))
(ensures (
let j = i `Prims.op_Multiply` k.parser_kind_low in
0 <= j /\
j + k.parser_kind_low <= Seq.length b /\ (
let b' = Seq.slice b j (Seq.length b) in
Some? (parse p b') /\ (
let (Some (l, _)) = parse (parse_list p) b in
let (Some (x, _)) = parse p b' in
x == L.index l i
))))
(decreases i)
let rec list_nth_constant_size_parser_correct #k #t p b i =
parser_kind_prop_equiv k p;
parse_list_eq p b;
if i = 0
then ()
else begin
M.mult_decomp i k.parser_kind_low;
list_nth_constant_size_parser_correct p (Seq.slice b k.parser_kind_low (Seq.length b)) (i - 1)
end
let clens_array_nth
(t: Type)
(elem_count: nat)
(i: nat { i < elem_count } )
: Tot (clens (array t elem_count) t)
= {
clens_cond = (fun _ -> True);
clens_get = (fun (l: array t elem_count) -> L.index l i);
}
#reset-options // re-enable non-linear arith to prove that multiplying two nats yields a nat
[@"opaque_to_smt"]
let array_nth_ghost''
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: GTot (nat)
= if (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length input
then (i `Prims.op_Multiply` k.parser_kind_low)
else (0) // dummy
#reset-options "--z3cliopt smt.arith.nl=false"
let array_nth_ghost_correct'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input))
(ensures (gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input)))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
parser_kind_prop_equiv k p;
fldata_to_array_inj s array_byte_size elem_count ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input;
let input0 = Seq.slice input 0 array_byte_size in
parse_strong_prefix (parse_fldata_strong (serialize_list _ s) array_byte_size) input input0;
list_nth_constant_size_parser_correct p input0 i;
let off = i `Prims.op_Multiply` k.parser_kind_low in
parse_strong_prefix p (Seq.slice input0 off (Seq.length input0)) (Seq.slice input off (Seq.length input))
let array_nth_ghost_correct
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
(input: bytes)
: Lemma
(gaccessor_post' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) input (array_nth_ghost'' s array_byte_size elem_count i input))
= reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i input);
Classical.move_requires (array_nth_ghost_correct' s array_byte_size elem_count i) input
[@"opaque_to_smt"]
let array_nth_ghost'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor' (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= fun input ->
array_nth_ghost_correct s array_byte_size elem_count i input;
array_nth_ghost'' s array_byte_size elem_count i input
[@"opaque_to_smt"]
let array_nth_ghost
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: nat {
fldata_array_precond k array_byte_size elem_count == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
i < elem_count
})
: Tot (gaccessor (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i))
= reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s array_byte_size elem_count i);
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s array_byte_size elem_count i);
M.distributivity_add_left i 1 k.parser_kind_low;
M.lemma_mult_le_right k.parser_kind_low (i + 1) elem_count;
assert ((i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= array_byte_size);
parser_kind_prop_equiv (parse_array_kind' array_byte_size) (parse_array s array_byte_size elem_count);
assert (forall x . gaccessor_pre (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) x ==> (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low <= Seq.length x);
gaccessor_prop_equiv (parse_array s array_byte_size elem_count) p (clens_array_nth t elem_count i) (array_nth_ghost' s array_byte_size elem_count i);
array_nth_ghost' s array_byte_size elem_count i
module B = LowStar.Buffer
inline_for_extraction
let array_nth
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(elem_count: nat)
(i: U32.t {
fldata_array_precond k (array_byte_size) (elem_count) == true /\
array_byte_size < 4294967296 /\
elem_count < 4294967296 /\
U32.v i < elem_count
})
: Tot (accessor (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)))
= fun #rrel #rel input pos ->
reveal_opaque (`%array_nth_ghost) (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost') (array_nth_ghost' s (array_byte_size) (elem_count) (U32.v i));
reveal_opaque (`%array_nth_ghost'') (array_nth_ghost'' s (array_byte_size) (elem_count) (U32.v i));
let h = HST.get () in
[@inline_let] let _ =
parser_kind_prop_equiv k p;
valid_facts (parse_array s (array_byte_size) (elem_count)) h input pos;
slice_access_eq h (array_nth_ghost s (array_byte_size) (elem_count) (U32.v i)) input pos;
fldata_to_array_inj s (array_byte_size) (elem_count) ();
parse_synth_eq (parse_fldata_strong (serialize_list _ s) (array_byte_size)) (fldata_to_array s array_byte_size elem_count ()) (bytes_of_slice_from h input pos);
list_nth_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 array_byte_size) (U32.v i)
in
pos `U32.add` (i `U32.mul` U32.uint_to_t k.parser_kind_low)
module HS = FStar.HyperStack
let valid_list_valid_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array' s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_exact_list p h input pos pos' ;
valid_exact_equiv (parse_list p) h input pos pos' ;
let len32 = pos' `U32.sub` pos in
list_length_constant_size_parser_correct p (Seq.slice (bytes_of_slice_from h input pos) 0 (U32.v len32));
contents_exact_eq (parse_list p) h input pos pos';
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos
let valid_list_valid_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h input pos pos' /\ (L.length (contents_list p h input pos pos') == elem_count \/ U32.v pos' - U32.v pos == array_byte_size)))
(ensures (
let x = contents_list p h input pos pos' in
L.length x == elem_count /\
U32.v pos' - U32.v pos == array_byte_size /\
valid_content_pos (parse_array s array_byte_size elem_count) h input pos x pos'
))
= valid_list_valid_array' s array_byte_size array_byte_size32 elem_count u h input pos pos' ;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_facts (parse_array s array_byte_size elem_count) h input pos
let valid_array_valid_list'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array' s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
let pos' = get_valid_pos (parse_array' s array_byte_size elem_count) h input pos in
let x = contents (parse_array' s array_byte_size elem_count) h input pos in
valid_synth h (parse_fldata_strong (serialize_list _ s) array_byte_size) (fldata_to_array s array_byte_size elem_count ()) input pos;
valid_facts (parse_fldata_strong (serialize_list _ s) array_byte_size) h input pos;
valid_exact_equiv (parse_list p) h input pos pos' ;
contents_exact_eq (parse_list p) h input pos pos' ;
valid_exact_list_valid_list p h input pos pos'
let valid_array_valid_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid (parse_array s array_byte_size elem_count) h input pos
))
(ensures (
let pos' = get_valid_pos (parse_array s array_byte_size elem_count) h input pos in
let x = contents (parse_array s array_byte_size elem_count) h input pos in
U32.v pos' - U32.v pos == array_byte_size /\
valid_list p h input pos pos' /\
contents_list p h input pos pos' == x
))
=
valid_facts (parse_array s array_byte_size elem_count) h input pos;
valid_facts (parse_array' s array_byte_size elem_count) h input pos;
valid_array_valid_list' s array_byte_size array_byte_size32 elem_count u h input pos
inline_for_extraction
let validate_array'
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array' s array_byte_size elem_count))
= validate_synth
(validate_fldata_strong (serialize_list _ s) (validate_list v ()) array_byte_size array_byte_size32)
(fldata_to_array s array_byte_size elem_count ())
()
inline_for_extraction
let validate_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (validator (parse_array s array_byte_size elem_count))
= if k.parser_kind_metadata = Some ParserKindMetadataTotal
then validate_total_constant_size (parse_array s array_byte_size elem_count) (FStar.Int.Cast.uint32_to_uint64 array_byte_size32) ()
else validate_array' s v array_byte_size array_byte_size32 elem_count u
inline_for_extraction
let jump_array
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(array_byte_size: nat)
(array_byte_size32: U32.t)
(elem_count: nat)
(u: unit {
fldata_array_precond k array_byte_size elem_count == true /\
U32.v array_byte_size32 == array_byte_size
})
: Tot (jumper (parse_array s array_byte_size elem_count))
= jump_constant_size (parse_array s array_byte_size elem_count) array_byte_size32 ()
inline_for_extraction
let validate_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max /\ array_byte_size_max < 4294967296 } )
: Tot (validator (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
validate_synth
(validate_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) (validate_list v ()) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let jump_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(u: unit {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(sz32: U32.t { U32.v sz32 == log256' array_byte_size_max } )
: Tot (jumper (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u))
= vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max u;
jump_synth
(jump_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s) ())
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
()
inline_for_extraction
let finalize_vlarray
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\ (
let vpos1 = U32.v pos + log256' array_byte_size_max in
vpos1 < 4294967296 /\ (
let pos1 = U32.uint_to_t vpos1 in
let len = U32.v pos' - vpos1 in
valid_list p h sl pos1 pos' /\ (
let count = L.length (contents_list p h sl pos1 pos') in
writable sl.base (U32.v pos) vpos1 h /\
((array_byte_size_min <= len /\ len <= array_byte_size_max) \/ (elem_count_min <= count /\ count <= elem_count_max))
)))))
(ensures (fun h _ h' ->
let pos1 = (U32.uint_to_t (U32.v pos + log256' array_byte_size_max)) in
let l = contents_list p h sl pos1 pos' in
B.modifies (loc_slice_from_to sl pos pos1) h h' /\
elem_count_min <= L.length l /\ L.length l <= elem_count_max /\
valid_content_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h' sl pos l pos'
))
= let h = HST.get () in
let pos1 = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
valid_list_valid_exact_list p h sl pos1 pos';
let l = Ghost.hide (contents_list p h sl pos1 pos') in
let _ : squash (let count = L.length (Ghost.reveal l) in elem_count_min <= count /\ count <= elem_count_max) =
valid_exact_serialize (serialize_list _ s) h sl pos1 pos' ;
Classical.move_requires (vldata_to_vlarray_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max) (Ghost.reveal l)
in
vlarray_to_vldata_correct array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (Ghost.reveal l);
finalize_bounded_vldata_strong_exact array_byte_size_min array_byte_size_max (serialize_list _ s) sl pos pos' ;
let h = HST.get () in
valid_synth h (parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s)) (vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) sl pos
let clens_vlarray_nth
(t: Type)
(min max: nat)
(i: nat)
: Tot (clens (vlarray t min max) t)
= {
clens_cond = (fun (l: vlarray t min max) -> i < L.length l);
clens_get = (fun (l: vlarray t min max) -> L.index l i);
}
inline_for_extraction
let vlarray_list_length
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true /\
valid (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos
))
(ensures (fun h res h' ->
let x = (contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos) in
let pos' = get_valid_pos (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
B.modifies B.loc_none h h' /\
U32.v res == L.length x /\
U32.v pos' == U32.v pos + (log256' array_byte_size_max) + (U32.v res `FStar.Mul.op_Star` k.parser_kind_low) /\
valid_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' /\
contents_list p h sl (pos `U32.add` U32.uint_to_t (log256' array_byte_size_max)) pos' == x
))
= let h = HST.get () in
[@inline_let]
let _ : unit =
let l = contents (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos in
let sq = bytes_of_slice_from h sl pos in
valid_facts (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) h sl pos;
valid_facts (parse_bounded_integer (log256' array_byte_size_max)) h sl pos;
vldata_to_vlarray_inj array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ();
parse_synth_eq
(parse_bounded_vldata_strong array_byte_size_min array_byte_size_max (serialize_list _ s))
(vldata_to_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ())
sq;
parse_vldata_gen_eq (log256' array_byte_size_max) (in_bounds array_byte_size_min array_byte_size_max) (parse_list p) sq;
let psq = parse (parse_bounded_integer (log256' array_byte_size_max)) sq in
let Some (ln, _) = psq in
list_length_constant_size_parser_correct p (Seq.slice sq (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v ln));
LowParse.Math.multiple_division_lemma (L.length l) k.parser_kind_low;
let pos_payload = pos `U32.add` U32.uint_to_t (log256' array_byte_size_max) in
let pos' = pos_payload `U32.add` ln in
valid_exact_equiv (parse_list p) h sl pos_payload pos';
contents_exact_eq (parse_list p) h sl pos_payload pos';
valid_exact_list_valid_list p h sl pos_payload pos'
in
[@inline_let]
let klow : U32.t =
U32.uint_to_t k.parser_kind_low
in
let blen = read_bounded_integer (log256' array_byte_size_max) sl pos in
blen `U32.div` klow
#push-options "--z3rlimit 16"
[@"opaque_to_smt"]
let vlarray_nth_ghost''
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: GTot (nat)
= if (log256' array_byte_size_max + (i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length input
then (log256' array_byte_size_max + (i `M.mult_nat` k.parser_kind_low))
else (0) // dummy
#pop-options
let uint32_size_intro
(x: nat)
: Lemma
(requires (x < 4294967296))
(ensures (FStar.UInt.size x 32))
= ()
inline_for_extraction
let vlarray_nth_compute
(a: nat)
(b: U32.t)
(c: U32.t)
(bound: Ghost.erased nat {
a + (U32.v b `Prims.op_Multiply` U32.v c) <= Ghost.reveal bound /\
Ghost.reveal bound < 4294967296
})
: Tot (z: U32.t { U32.v z == a + (U32.v b `Prims.op_Multiply` U32.v c)})
= FStar.Math.Lemmas.nat_times_nat_is_nat (U32.v b) (U32.v c);
uint32_size_intro (U32.v b `Prims.op_Multiply` U32.v c);
U32.uint_to_t a `U32.add` (b `U32.mul` c)
inline_for_extraction
let vlarray_nth_body
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: U32.t {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: Ghost.erased bytes)
: Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre
(parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max (U32.v i)) (Ghost.reveal input)))
(ensures (fun y ->
U32.v y == (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input))))
=
reveal_opaque (`%vlarray_nth_ghost'') (vlarray_nth_ghost'' array_byte_size_min array_byte_size_max s elem_count_min elem_count_max (U32.v i) (Ghost.reveal input));
[@inline_let]
let _ : squash ((log256' array_byte_size_max + (U32.v i `Prims.op_Multiply` k.parser_kind_low) + k.parser_kind_low) <= Seq.length (Ghost.reveal input)) =
parse_vlarray_eq_some array_byte_size_min array_byte_size_max s elem_count_min elem_count_max () (Ghost.reveal input);
let pi = parse (parse_bounded_integer (log256' array_byte_size_max)) (Ghost.reveal input) in
let lc = Some?.v pi in
let len = fst lc in
let c_len = snd lc in
let sq = Seq.slice (Ghost.reveal input) (log256' array_byte_size_max) (log256' array_byte_size_max + U32.v len) in
list_nth_constant_size_parser_correct p sq (U32.v i)
in
vlarray_nth_compute (log256' array_byte_size_max) i (U32.uint_to_t k.parser_kind_low) (Ghost.hide (Seq.length (Ghost.reveal input)))
#reset-options "--z3cliopt smt.arith.nl=false --z3refresh --using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--z3rlimit 32"
let vlarray_nth_ghost_correct'
(array_byte_size_min: nat)
(array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min: nat)
(elem_count_max: nat)
(i: nat {
vldata_vlarray_precond array_byte_size_min array_byte_size_max p elem_count_min elem_count_max == true
})
(input: bytes)
: Lemma
(requires (gaccessor_pre (parse_vlarray array_byte_size_min array_byte_size_max s elem_count_min elem_count_max ()) p (clens_vlarray_nth t elem_count_min elem_count_max i) input)) | false | false | LowParse.Low.Array.fst | {
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vlarray_nth_ghost_correct'
(array_byte_size_min array_byte_size_max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(elem_count_min elem_count_max: nat)
(i:
nat
{ vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true })
(input: bytes)
: Lemma
(requires
(gaccessor_pre (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input))
(ensures
(gaccessor_post' (parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(clens_vlarray_nth t elem_count_min elem_count_max i)
input
(vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input))) | [] | LowParse.Low.Array.vlarray_nth_ghost_correct' | {
"file_name": "src/lowparse/LowParse.Low.Array.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
array_byte_size_min: Prims.nat ->
array_byte_size_max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
elem_count_min: Prims.nat ->
elem_count_max: Prims.nat ->
i:
Prims.nat
{ LowParse.Spec.Array.vldata_vlarray_precond array_byte_size_min
array_byte_size_max
p
elem_count_min
elem_count_max ==
true } ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(LowParse.Low.Array.clens_vlarray_nth t elem_count_min elem_count_max i)
input)
(ensures
LowParse.Low.Base.Spec.gaccessor_post' (LowParse.Spec.Array.parse_vlarray array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
())
p
(LowParse.Low.Array.clens_vlarray_nth t elem_count_min elem_count_max i)
input
(LowParse.Low.Array.vlarray_nth_ghost'' array_byte_size_min
array_byte_size_max
s
elem_count_min
elem_count_max
i
input)) | {
"end_col": 3,
"end_line": 654,
"start_col": 2,
"start_line": 644
} |
Prims.Tot | val subst1 (n: namedv) (t1 t2: term) : term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2 | val subst1 (n: namedv) (t1 t2: term) : term
let subst1 (n: namedv) (t1 t2: term) : term = | false | null | false | subst_term [NT n t1] t2 | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.namedv",
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Builtins.subst_term",
"Prims.Cons",
"FStar.Stubs.Syntax.Syntax.subst_elt",
"FStar.Stubs.Syntax.Syntax.NT",
"Prims.Nil"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst1 (n: namedv) (t1 t2: term) : term | [] | FStar.Reflection.V2.Derived.subst1 | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
n: FStar.Reflection.Types.namedv ->
t1: FStar.Reflection.Types.term ->
t2: FStar.Reflection.Types.term
-> FStar.Reflection.Types.term | {
"end_col": 25,
"end_line": 47,
"start_col": 2,
"start_line": 47
} |
Prims.Tot | val collect_arr_ln_bs : typ -> list binder * comp | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c) | val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t = | false | null | false | let bs, c = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c) | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.typ",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_arr'",
"Prims.Nil",
"FStar.Reflection.V2.Builtins.pack_comp",
"FStar.Reflection.V2.Data.C_Total"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_arr_ln_bs : typ -> list binder * comp | [] | FStar.Reflection.V2.Derived.collect_arr_ln_bs | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.typ
-> Prims.list FStar.Reflection.Types.binder * FStar.Reflection.Types.comp | {
"end_col": 29,
"end_line": 137,
"start_col": 25,
"start_line": 135
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_subst n s = List.Tot.map (shift n) s | let shift_subst n s = | false | null | false | List.Tot.map (shift n) s | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.list",
"FStar.Stubs.Syntax.Syntax.subst_elt",
"FStar.List.Tot.Base.map",
"FStar.Reflection.V2.Derived.shift"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_subst : n: Prims.int -> s: Prims.list FStar.Stubs.Syntax.Syntax.subst_elt
-> Prims.list FStar.Stubs.Syntax.Syntax.subst_elt | [] | FStar.Reflection.V2.Derived.shift_subst | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | n: Prims.int -> s: Prims.list FStar.Stubs.Syntax.Syntax.subst_elt
-> Prims.list FStar.Stubs.Syntax.Syntax.subst_elt | {
"end_col": 46,
"end_line": 44,
"start_col": 22,
"start_line": 44
} |
|
Prims.Tot | val mk_strcat (t1 t2: term) : term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2] | val mk_strcat (t1 t2: term) : term
let mk_strcat (t1 t2: term) : term = | false | null | false | mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2] | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Reflection.V2.Builtins.pack_ln",
"FStar.Reflection.V2.Data.Tv_FVar",
"FStar.Reflection.V2.Builtins.pack_fv",
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s)) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_strcat (t1 t2: term) : term | [] | FStar.Reflection.V2.Derived.mk_strcat | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t1: FStar.Reflection.Types.term -> t2: FStar.Reflection.Types.term -> FStar.Reflection.Types.term | {
"end_col": 71,
"end_line": 161,
"start_col": 4,
"start_line": 161
} |
Prims.Tot | val collect_app_ln : term -> term * list argv | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let collect_app_ln = collect_app_ln' [] | val collect_app_ln : term -> term * list argv
let collect_app_ln = | false | null | false | collect_app_ln' [] | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.V2.Derived.collect_app_ln'",
"Prims.Nil",
"FStar.Reflection.V2.Data.argv"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_app_ln : term -> term * list argv | [] | FStar.Reflection.V2.Derived.collect_app_ln | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Reflection.Types.term
-> FStar.Reflection.Types.term * Prims.list FStar.Reflection.V2.Data.argv | {
"end_col": 39,
"end_line": 98,
"start_col": 21,
"start_line": 98
} |
Prims.Tot | val push_binding (e: env) (b: binding) : env | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv | val push_binding (e: env) (b: binding) : env
let push_binding (e: env) (b: binding) : env = | false | null | false | let nv:namedv = pack_namedv ({ uniq = b.uniq; sort = seal b.sort; ppname = b.ppname }) in
push_namedv e nv | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.env",
"FStar.Reflection.V2.Data.binding",
"FStar.Reflection.V2.Builtins.push_namedv",
"FStar.Reflection.Types.namedv",
"FStar.Reflection.V2.Builtins.pack_namedv",
"FStar.Reflection.V2.Data.Mknamedv_view",
"FStar.Reflection.V2.Data.__proj__Mkbinding__item__uniq",
"FStar.Sealed.seal",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V2.Data.__proj__Mkbinding__item__sort",
"FStar.Reflection.V2.Data.__proj__Mkbinding__item__ppname"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
} | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val push_binding (e: env) (b: binding) : env | [] | FStar.Reflection.V2.Derived.push_binding | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | e: FStar.Reflection.Types.env -> b: FStar.Reflection.V2.Data.binding -> FStar.Reflection.Types.env | {
"end_col": 18,
"end_line": 78,
"start_col": 44,
"start_line": 71
} |
Prims.Tot | val add_check_with : vconfig -> sigelt -> Tot sigelt | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_check_with vcfg se =
let attrs = sigelt_attrs se in
let vcfg_t = embed_vconfig vcfg in
let t = `(check_with (`#vcfg_t)) in
set_sigelt_attrs (t :: attrs) se | val add_check_with : vconfig -> sigelt -> Tot sigelt
let add_check_with vcfg se = | false | null | false | let attrs = sigelt_attrs se in
let vcfg_t = embed_vconfig vcfg in
let t = `(check_with (`#vcfg_t)) in
set_sigelt_attrs (t :: attrs) se | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.VConfig.vconfig",
"FStar.Reflection.Types.sigelt",
"FStar.Reflection.V2.Builtins.set_sigelt_attrs",
"Prims.Cons",
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Builtins.embed_vconfig",
"Prims.list",
"FStar.Reflection.V2.Builtins.sigelt_attrs"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2]
let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t]
let mk_cons_t (ty h t : term) : term =
mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)]
let rec mk_list (ts : list term) : term =
match ts with
| [] -> pack_ln (Tv_FVar (pack_fv nil_qn))
| t::ts -> mk_cons t (mk_list ts)
let mktuple_n (ts : list term{List.Tot.Base.length ts <= 8}) : term =
match List.Tot.Base.length ts with
| 0 -> pack_ln (Tv_Const C_Unit)
| 1 -> let [x] = ts in x
| n -> begin
let qn = match n with
| 2 -> mktuple2_qn
| 3 -> mktuple3_qn
| 4 -> mktuple4_qn
| 5 -> mktuple5_qn
| 6 -> mktuple6_qn
| 7 -> mktuple7_qn
| 8 -> mktuple8_qn
in mk_e_app (pack_ln (Tv_FVar (pack_fv qn))) ts
end
let destruct_tuple (t : term) : option (list term) =
let head, args = collect_app_ln t in
match inspect_ln head with
| Tv_FVar fv ->
if List.Tot.Base.mem
(inspect_fv fv) [mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn;
mktuple6_qn; mktuple7_qn; mktuple8_qn]
then Some (List.Tot.Base.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []) args)
else None
| _ -> None
let mkpair (t1 t2 : term) : term =
mktuple_n [t1;t2]
let rec head (t : term) : term =
match inspect_ln t with
| Tv_Match t _ _
| Tv_Let _ _ _ t _
| Tv_Abs _ t
| Tv_Refine _ t
| Tv_App t _
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ -> head t
| Tv_Unknown
| Tv_Uvar _ _
| Tv_Const _
| Tv_Type _
| Tv_Var _
| Tv_BVar _
| Tv_FVar _
| Tv_UInst _ _
| Tv_Arrow _ _
| Tv_Unsupp -> t
(** Checks if a term `t` is equal to some FV (a top level name).
Ignores universes and ascriptions. *)
let is_fvar (t : term) (nm:string) : bool =
match inspect_ln_unascribe t with
| Tv_FVar fv
| Tv_UInst fv _ -> implode_qn (inspect_fv fv) = nm
| _ -> false
(** Checks if a term `t` is equal to any FV (a top level name) from
those given in the list. Ignores universes and ascriptions. *)
let rec is_any_fvar (t : term) (nms:list string) : bool =
match nms with
| [] -> false
| v::vs -> is_fvar t v || is_any_fvar t vs
let is_uvar (t : term) : bool =
match inspect_ln (head t) with
| Tv_Uvar _ _ -> true
| _ -> false
let binder_set_qual (q:aqualv) (b:binder) : Tot binder =
let bview = inspect_binder b in
pack_binder { bview with qual=q }
(** Set a vconfig for a sigelt *) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_check_with : vconfig -> sigelt -> Tot sigelt | [] | FStar.Reflection.V2.Derived.add_check_with | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | vcfg: FStar.VConfig.vconfig -> se: FStar.Reflection.Types.sigelt -> FStar.Reflection.Types.sigelt | {
"end_col": 34,
"end_line": 258,
"start_col": 28,
"start_line": 254
} |
Prims.Tot | val collect_arr_ln : typ -> list typ * comp | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c | val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t = | false | null | false | let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.typ",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.map",
"FStar.Reflection.V2.Derived.type_of_binder",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_arr_ln_bs"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_arr_ln : typ -> list typ * comp | [] | FStar.Reflection.V2.Derived.collect_arr_ln | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.typ -> Prims.list FStar.Reflection.Types.typ * FStar.Reflection.Types.comp | {
"end_col": 42,
"end_line": 142,
"start_col": 22,
"start_line": 140
} |
Prims.Tot | val mk_stringlit (s: string) : term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s)) | val mk_stringlit (s: string) : term
let mk_stringlit (s: string) : term = | false | null | false | pack_ln (Tv_Const (C_String s)) | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"Prims.string",
"FStar.Reflection.V2.Builtins.pack_ln",
"FStar.Reflection.V2.Data.Tv_Const",
"FStar.Reflection.V2.Data.C_String",
"FStar.Reflection.Types.term"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_stringlit (s: string) : term | [] | FStar.Reflection.V2.Derived.mk_stringlit | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> FStar.Reflection.Types.term | {
"end_col": 35,
"end_line": 158,
"start_col": 4,
"start_line": 158
} |
Prims.Tot | val type_of_binder (b: binder) : typ | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let type_of_binder (b : binder) : typ =
(inspect_binder b).sort | val type_of_binder (b: binder) : typ
let type_of_binder (b: binder) : typ = | false | null | false | (inspect_binder b).sort | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.binder",
"FStar.Reflection.V2.Data.__proj__Mkbinder_view__item__sort",
"FStar.Reflection.V2.Builtins.inspect_binder",
"FStar.Reflection.Types.typ"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val type_of_binder (b: binder) : typ | [] | FStar.Reflection.V2.Derived.type_of_binder | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: FStar.Reflection.Types.binder -> FStar.Reflection.Types.typ | {
"end_col": 27,
"end_line": 81,
"start_col": 4,
"start_line": 81
} |
Prims.Tot | val mk_cons (h t: term) : term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t] | val mk_cons (h t: term) : term
let mk_cons (h t: term) : term = | false | null | false | mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t] | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Reflection.V2.Builtins.pack_ln",
"FStar.Reflection.V2.Data.Tv_FVar",
"FStar.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.cons_qn",
"Prims.Cons",
"Prims.Nil"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2] | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_cons (h t: term) : term | [] | FStar.Reflection.V2.Derived.mk_cons | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | h: FStar.Reflection.Types.term -> t: FStar.Reflection.Types.term -> FStar.Reflection.Types.term | {
"end_col": 56,
"end_line": 164,
"start_col": 3,
"start_line": 164
} |
Prims.Tot | val compare_bv (v1 v2: bv) : order | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index | val compare_bv (v1 v2: bv) : order
let compare_bv (v1 v2: bv) : order = | false | null | false | Order.compare_int (inspect_bv v1).index (inspect_bv v2).index | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.bv",
"FStar.Order.compare_int",
"FStar.Reflection.V2.Data.__proj__Mkbv_view__item__index",
"FStar.Reflection.V2.Builtins.inspect_bv",
"FStar.Order.order"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_bv (v1 v2: bv) : order | [] | FStar.Reflection.V2.Derived.compare_bv | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v1: FStar.Reflection.Types.bv -> v2: FStar.Reflection.Types.bv -> FStar.Order.order | {
"end_col": 63,
"end_line": 32,
"start_col": 2,
"start_line": 32
} |
Prims.Tot | val is_uvar (t: term) : bool | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_uvar (t : term) : bool =
match inspect_ln (head t) with
| Tv_Uvar _ _ -> true
| _ -> false | val is_uvar (t: term) : bool
let is_uvar (t: term) : bool = | false | null | false | match inspect_ln (head t) with
| Tv_Uvar _ _ -> true
| _ -> false | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Builtins.inspect_ln",
"FStar.Reflection.V2.Derived.head",
"Prims.nat",
"FStar.Reflection.Types.ctx_uvar_and_subst",
"FStar.Reflection.V2.Data.term_view",
"Prims.bool"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2]
let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t]
let mk_cons_t (ty h t : term) : term =
mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)]
let rec mk_list (ts : list term) : term =
match ts with
| [] -> pack_ln (Tv_FVar (pack_fv nil_qn))
| t::ts -> mk_cons t (mk_list ts)
let mktuple_n (ts : list term{List.Tot.Base.length ts <= 8}) : term =
match List.Tot.Base.length ts with
| 0 -> pack_ln (Tv_Const C_Unit)
| 1 -> let [x] = ts in x
| n -> begin
let qn = match n with
| 2 -> mktuple2_qn
| 3 -> mktuple3_qn
| 4 -> mktuple4_qn
| 5 -> mktuple5_qn
| 6 -> mktuple6_qn
| 7 -> mktuple7_qn
| 8 -> mktuple8_qn
in mk_e_app (pack_ln (Tv_FVar (pack_fv qn))) ts
end
let destruct_tuple (t : term) : option (list term) =
let head, args = collect_app_ln t in
match inspect_ln head with
| Tv_FVar fv ->
if List.Tot.Base.mem
(inspect_fv fv) [mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn;
mktuple6_qn; mktuple7_qn; mktuple8_qn]
then Some (List.Tot.Base.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []) args)
else None
| _ -> None
let mkpair (t1 t2 : term) : term =
mktuple_n [t1;t2]
let rec head (t : term) : term =
match inspect_ln t with
| Tv_Match t _ _
| Tv_Let _ _ _ t _
| Tv_Abs _ t
| Tv_Refine _ t
| Tv_App t _
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ -> head t
| Tv_Unknown
| Tv_Uvar _ _
| Tv_Const _
| Tv_Type _
| Tv_Var _
| Tv_BVar _
| Tv_FVar _
| Tv_UInst _ _
| Tv_Arrow _ _
| Tv_Unsupp -> t
(** Checks if a term `t` is equal to some FV (a top level name).
Ignores universes and ascriptions. *)
let is_fvar (t : term) (nm:string) : bool =
match inspect_ln_unascribe t with
| Tv_FVar fv
| Tv_UInst fv _ -> implode_qn (inspect_fv fv) = nm
| _ -> false
(** Checks if a term `t` is equal to any FV (a top level name) from
those given in the list. Ignores universes and ascriptions. *)
let rec is_any_fvar (t : term) (nms:list string) : bool =
match nms with
| [] -> false
| v::vs -> is_fvar t v || is_any_fvar t vs | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_uvar (t: term) : bool | [] | FStar.Reflection.V2.Derived.is_uvar | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> Prims.bool | {
"end_col": 16,
"end_line": 246,
"start_col": 4,
"start_line": 244
} |
Prims.Tot | val mk_e_app (t: term) (args: list term) : Tot term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args) | val mk_e_app (t: term) (args: list term) : Tot term
let mk_e_app (t: term) (args: list term) : Tot term = | false | null | false | let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args) | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.V2.Derived.mk_app",
"FStar.List.Tot.Base.map",
"FStar.Reflection.V2.Data.argv",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Data.aqualv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V2.Data.Q_Explicit"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_e_app (t: term) (args: list term) : Tot term | [] | FStar.Reflection.V2.Derived.mk_e_app | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> args: Prims.list FStar.Reflection.Types.term
-> FStar.Reflection.Types.term | {
"end_col": 39,
"end_line": 108,
"start_col": 55,
"start_line": 106
} |
Prims.Tot | val compare_namedv (v1 v2: namedv) : order | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq | val compare_namedv (v1 v2: namedv) : order
let compare_namedv (v1 v2: namedv) : order = | false | null | false | Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.namedv",
"FStar.Order.compare_int",
"FStar.Reflection.V2.Data.__proj__Mknamedv_view__item__uniq",
"FStar.Reflection.V2.Builtins.inspect_namedv",
"FStar.Order.order"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_namedv (v1 v2: namedv) : order | [] | FStar.Reflection.V2.Derived.compare_namedv | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v1: FStar.Reflection.Types.namedv -> v2: FStar.Reflection.Types.namedv -> FStar.Order.order | {
"end_col": 69,
"end_line": 35,
"start_col": 2,
"start_line": 35
} |
Prims.Tot | val binder_set_qual (q: aqualv) (b: binder) : Tot binder | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let binder_set_qual (q:aqualv) (b:binder) : Tot binder =
let bview = inspect_binder b in
pack_binder { bview with qual=q } | val binder_set_qual (q: aqualv) (b: binder) : Tot binder
let binder_set_qual (q: aqualv) (b: binder) : Tot binder = | false | null | false | let bview = inspect_binder b in
pack_binder ({ bview with qual = q }) | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.V2.Data.aqualv",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V2.Builtins.pack_binder",
"FStar.Reflection.V2.Data.Mkbinder_view",
"FStar.Reflection.V2.Data.__proj__Mkbinder_view__item__sort",
"FStar.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs",
"FStar.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname",
"FStar.Reflection.V2.Data.binder_view",
"Prims.precedes",
"FStar.Reflection.V2.Builtins.inspect_binder"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2]
let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t]
let mk_cons_t (ty h t : term) : term =
mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)]
let rec mk_list (ts : list term) : term =
match ts with
| [] -> pack_ln (Tv_FVar (pack_fv nil_qn))
| t::ts -> mk_cons t (mk_list ts)
let mktuple_n (ts : list term{List.Tot.Base.length ts <= 8}) : term =
match List.Tot.Base.length ts with
| 0 -> pack_ln (Tv_Const C_Unit)
| 1 -> let [x] = ts in x
| n -> begin
let qn = match n with
| 2 -> mktuple2_qn
| 3 -> mktuple3_qn
| 4 -> mktuple4_qn
| 5 -> mktuple5_qn
| 6 -> mktuple6_qn
| 7 -> mktuple7_qn
| 8 -> mktuple8_qn
in mk_e_app (pack_ln (Tv_FVar (pack_fv qn))) ts
end
let destruct_tuple (t : term) : option (list term) =
let head, args = collect_app_ln t in
match inspect_ln head with
| Tv_FVar fv ->
if List.Tot.Base.mem
(inspect_fv fv) [mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn;
mktuple6_qn; mktuple7_qn; mktuple8_qn]
then Some (List.Tot.Base.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []) args)
else None
| _ -> None
let mkpair (t1 t2 : term) : term =
mktuple_n [t1;t2]
let rec head (t : term) : term =
match inspect_ln t with
| Tv_Match t _ _
| Tv_Let _ _ _ t _
| Tv_Abs _ t
| Tv_Refine _ t
| Tv_App t _
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ -> head t
| Tv_Unknown
| Tv_Uvar _ _
| Tv_Const _
| Tv_Type _
| Tv_Var _
| Tv_BVar _
| Tv_FVar _
| Tv_UInst _ _
| Tv_Arrow _ _
| Tv_Unsupp -> t
(** Checks if a term `t` is equal to some FV (a top level name).
Ignores universes and ascriptions. *)
let is_fvar (t : term) (nm:string) : bool =
match inspect_ln_unascribe t with
| Tv_FVar fv
| Tv_UInst fv _ -> implode_qn (inspect_fv fv) = nm
| _ -> false
(** Checks if a term `t` is equal to any FV (a top level name) from
those given in the list. Ignores universes and ascriptions. *)
let rec is_any_fvar (t : term) (nms:list string) : bool =
match nms with
| [] -> false
| v::vs -> is_fvar t v || is_any_fvar t vs
let is_uvar (t : term) : bool =
match inspect_ln (head t) with
| Tv_Uvar _ _ -> true
| _ -> false | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val binder_set_qual (q: aqualv) (b: binder) : Tot binder | [] | FStar.Reflection.V2.Derived.binder_set_qual | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | q: FStar.Reflection.V2.Data.aqualv -> b: FStar.Reflection.Types.binder
-> FStar.Reflection.Types.binder | {
"end_col": 35,
"end_line": 250,
"start_col": 56,
"start_line": 248
} |
Prims.Tot | val mk_cons_t (ty h t: term) : term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_cons_t (ty h t : term) : term =
mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)] | val mk_cons_t (ty h t: term) : term
let mk_cons_t (ty h t: term) : term = | false | null | false | mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)] | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.mk_app",
"FStar.Reflection.V2.Builtins.pack_ln",
"FStar.Reflection.V2.Data.Tv_FVar",
"FStar.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.cons_qn",
"Prims.Cons",
"FStar.Reflection.V2.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V2.Data.aqualv",
"FStar.Reflection.V2.Data.Q_Implicit",
"FStar.Reflection.V2.Data.Q_Explicit",
"Prims.Nil"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2]
let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t] | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_cons_t (ty h t: term) : term | [] | FStar.Reflection.V2.Derived.mk_cons_t | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ty: FStar.Reflection.Types.term -> h: FStar.Reflection.Types.term -> t: FStar.Reflection.Types.term
-> FStar.Reflection.Types.term | {
"end_col": 100,
"end_line": 167,
"start_col": 3,
"start_line": 167
} |
Prims.Tot | val un_uinst (t: term) : term | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let un_uinst (t:term) : term =
match inspect_ln t with
| Tv_UInst fv _ -> pack_ln (Tv_FVar fv)
| _ -> t | val un_uinst (t: term) : term
let un_uinst (t: term) : term = | false | null | false | match inspect_ln t with
| Tv_UInst fv _ -> pack_ln (Tv_FVar fv)
| _ -> t | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Builtins.inspect_ln",
"FStar.Reflection.Types.fv",
"FStar.Reflection.V2.Data.universes",
"FStar.Reflection.V2.Builtins.pack_ln",
"FStar.Reflection.V2.Data.Tv_FVar",
"FStar.Reflection.V2.Data.term_view"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2]
let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t]
let mk_cons_t (ty h t : term) : term =
mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)]
let rec mk_list (ts : list term) : term =
match ts with
| [] -> pack_ln (Tv_FVar (pack_fv nil_qn))
| t::ts -> mk_cons t (mk_list ts)
let mktuple_n (ts : list term{List.Tot.Base.length ts <= 8}) : term =
match List.Tot.Base.length ts with
| 0 -> pack_ln (Tv_Const C_Unit)
| 1 -> let [x] = ts in x
| n -> begin
let qn = match n with
| 2 -> mktuple2_qn
| 3 -> mktuple3_qn
| 4 -> mktuple4_qn
| 5 -> mktuple5_qn
| 6 -> mktuple6_qn
| 7 -> mktuple7_qn
| 8 -> mktuple8_qn
in mk_e_app (pack_ln (Tv_FVar (pack_fv qn))) ts
end
let destruct_tuple (t : term) : option (list term) =
let head, args = collect_app_ln t in
match inspect_ln head with
| Tv_FVar fv ->
if List.Tot.Base.mem
(inspect_fv fv) [mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn;
mktuple6_qn; mktuple7_qn; mktuple8_qn]
then Some (List.Tot.Base.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []) args)
else None
| _ -> None
let mkpair (t1 t2 : term) : term =
mktuple_n [t1;t2]
let rec head (t : term) : term =
match inspect_ln t with
| Tv_Match t _ _
| Tv_Let _ _ _ t _
| Tv_Abs _ t
| Tv_Refine _ t
| Tv_App t _
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ -> head t
| Tv_Unknown
| Tv_Uvar _ _
| Tv_Const _
| Tv_Type _
| Tv_Var _
| Tv_BVar _
| Tv_FVar _
| Tv_UInst _ _
| Tv_Arrow _ _
| Tv_Unsupp -> t
(** Checks if a term `t` is equal to some FV (a top level name).
Ignores universes and ascriptions. *)
let is_fvar (t : term) (nm:string) : bool =
match inspect_ln_unascribe t with
| Tv_FVar fv
| Tv_UInst fv _ -> implode_qn (inspect_fv fv) = nm
| _ -> false
(** Checks if a term `t` is equal to any FV (a top level name) from
those given in the list. Ignores universes and ascriptions. *)
let rec is_any_fvar (t : term) (nms:list string) : bool =
match nms with
| [] -> false
| v::vs -> is_fvar t v || is_any_fvar t vs
let is_uvar (t : term) : bool =
match inspect_ln (head t) with
| Tv_Uvar _ _ -> true
| _ -> false
let binder_set_qual (q:aqualv) (b:binder) : Tot binder =
let bview = inspect_binder b in
pack_binder { bview with qual=q }
(** Set a vconfig for a sigelt *)
val add_check_with : vconfig -> sigelt -> Tot sigelt
let add_check_with vcfg se =
let attrs = sigelt_attrs se in
let vcfg_t = embed_vconfig vcfg in
let t = `(check_with (`#vcfg_t)) in
set_sigelt_attrs (t :: attrs) se | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val un_uinst (t: term) : term | [] | FStar.Reflection.V2.Derived.un_uinst | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> FStar.Reflection.Types.term | {
"end_col": 10,
"end_line": 263,
"start_col": 2,
"start_line": 261
} |
Prims.Tot | val fv_to_string (fv: fv) : string | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv) | val fv_to_string (fv: fv) : string
let fv_to_string (fv: fv) : string = | false | null | false | implode_qn (inspect_fv fv) | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.fv",
"FStar.Reflection.V2.Builtins.implode_qn",
"FStar.Reflection.V2.Builtins.inspect_fv",
"Prims.string"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t') | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fv_to_string (fv: fv) : string | [] | FStar.Reflection.V2.Derived.fv_to_string | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | fv: FStar.Reflection.Types.fv -> Prims.string | {
"end_col": 62,
"end_line": 155,
"start_col": 36,
"start_line": 155
} |
Prims.Tot | val is_fvar (t: term) (nm: string) : bool | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_fvar (t : term) (nm:string) : bool =
match inspect_ln_unascribe t with
| Tv_FVar fv
| Tv_UInst fv _ -> implode_qn (inspect_fv fv) = nm
| _ -> false | val is_fvar (t: term) (nm: string) : bool
let is_fvar (t: term) (nm: string) : bool = | false | null | false | match inspect_ln_unascribe t with
| Tv_FVar fv | Tv_UInst fv _ -> implode_qn (inspect_fv fv) = nm
| _ -> false | {
"checked_file": "FStar.Reflection.V2.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Order.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"Prims.string",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.fv",
"Prims.op_Equality",
"FStar.Reflection.V2.Builtins.implode_qn",
"FStar.Reflection.V2.Builtins.inspect_fv",
"FStar.Reflection.V2.Data.universes",
"FStar.Reflection.V2.Data.term_view",
"Prims.bool"
] | [] | (*
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.Reflection.V2.Derived
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Order
open FStar.VConfig
let rec inspect_ln_unascribe (t:term) : tv:term_view{tv << t /\ notAscription tv} =
match inspect_ln t with
| Tv_AscribedT t' _ _ _
| Tv_AscribedC t' _ _ _ -> inspect_ln_unascribe t'
| tv -> tv
let compare_bv (v1 v2 : bv) : order =
Order.compare_int (inspect_bv v1).index (inspect_bv v2).index
let compare_namedv (v1 v2 : namedv) : order =
Order.compare_int (inspect_namedv v1).uniq (inspect_namedv v2).uniq
let shift n s = match s with
| DB i t -> DB (i+n) t
| DT i t -> DT (i+n) t
| UN i t -> UN (i+n) t
| NM x i -> NM x (i+n)
| UD x i -> UD x (i+n)
| NT _ _ -> s
let shift_subst n s = List.Tot.map (shift n) s
let subst1 (n:namedv) (t1:term) (t2:term) : term =
subst_term [NT n t1] t2
(*
* AR: add versions that take attributes as arguments?
*)
let mk_binder (nm : string) (sort : typ) : simple_binder =
let bv : binder_view = {
ppname = seal nm;
qual = Q_Explicit;
attrs = [];
sort = sort;
}
in
inspect_pack_binder bv;
pack_binder bv
let mk_implicit_binder (nm : string) (sort : typ) : binder =
pack_binder {
ppname = seal nm;
qual = Q_Implicit;
attrs = [];
sort = sort;
}
let push_binding (e:env) (b:binding) : env =
let nv : namedv = pack_namedv {
uniq = b.uniq;
sort = seal b.sort;
ppname = b.ppname;
}
in
push_namedv e nv
let type_of_binder (b : binder) : typ =
(inspect_binder b).sort
val flatten_name : name -> Tot string
let rec flatten_name ns =
match ns with
| [] -> ""
| [n] -> n
| n::ns -> n ^ "." ^ flatten_name ns
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app_ln' (args : list argv) (t : term) : Tot (term * list argv) (decreases t) =
match inspect_ln_unascribe t with
| Tv_App l r ->
collect_app_ln' (r::args) l
| _ -> (t, args)
val collect_app_ln : term -> term * list argv
let collect_app_ln = collect_app_ln' []
let rec mk_app (t : term) (args : list argv) : Tot term (decreases args) =
match args with
| [] -> t
| (x::xs) -> mk_app (pack_ln (Tv_App t x)) xs
// Helper for when all arguments are explicit
let mk_e_app (t : term) (args : list term) : Tot term =
let e t = (t, Q_Explicit) in
mk_app t (List.Tot.Base.map e args)
let u_unk : universe = pack_universe Uv_Unk
let rec mk_tot_arr_ln (bs: list binder) (cod : term) : Tot term (decreases bs) =
match bs with
| [] -> cod
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr_ln bs cod))))
let rec mk_arr_ln (bs: list binder{~(Nil? bs)}) (cod : comp) : Tot term (decreases bs) =
match bs with
| [b] -> pack_ln (Tv_Arrow b cod)
| (b::bs) -> pack_ln (Tv_Arrow b (pack_comp (C_Total (mk_arr_ln bs cod))))
let rec collect_arr' (bs : list binder) (c : comp) : Tot (list binder * comp) (decreases c) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_ln_bs : typ -> list binder * comp
let collect_arr_ln_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr_ln : typ -> list typ * comp
let collect_arr_ln t =
let bs, c = collect_arr_ln_bs t in
List.Tot.Base.map type_of_binder bs, c
let rec collect_abs' (bs : list binder) (t : term) : Tot (list binder * term) (decreases t) =
match inspect_ln_unascribe t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs_ln : term -> list binder * term
let collect_abs_ln t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
let fv_to_string (fv:fv) : string = implode_qn (inspect_fv fv)
let mk_stringlit (s : string) : term =
pack_ln (Tv_Const (C_String s))
let mk_strcat (t1 t2 : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv ["Prims"; "strcat"]))) [t1; t2]
let mk_cons (h t : term) : term =
mk_e_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [h; t]
let mk_cons_t (ty h t : term) : term =
mk_app (pack_ln (Tv_FVar (pack_fv cons_qn))) [(ty, Q_Implicit); (h, Q_Explicit); (t, Q_Explicit)]
let rec mk_list (ts : list term) : term =
match ts with
| [] -> pack_ln (Tv_FVar (pack_fv nil_qn))
| t::ts -> mk_cons t (mk_list ts)
let mktuple_n (ts : list term{List.Tot.Base.length ts <= 8}) : term =
match List.Tot.Base.length ts with
| 0 -> pack_ln (Tv_Const C_Unit)
| 1 -> let [x] = ts in x
| n -> begin
let qn = match n with
| 2 -> mktuple2_qn
| 3 -> mktuple3_qn
| 4 -> mktuple4_qn
| 5 -> mktuple5_qn
| 6 -> mktuple6_qn
| 7 -> mktuple7_qn
| 8 -> mktuple8_qn
in mk_e_app (pack_ln (Tv_FVar (pack_fv qn))) ts
end
let destruct_tuple (t : term) : option (list term) =
let head, args = collect_app_ln t in
match inspect_ln head with
| Tv_FVar fv ->
if List.Tot.Base.mem
(inspect_fv fv) [mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn;
mktuple6_qn; mktuple7_qn; mktuple8_qn]
then Some (List.Tot.Base.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []) args)
else None
| _ -> None
let mkpair (t1 t2 : term) : term =
mktuple_n [t1;t2]
let rec head (t : term) : term =
match inspect_ln t with
| Tv_Match t _ _
| Tv_Let _ _ _ t _
| Tv_Abs _ t
| Tv_Refine _ t
| Tv_App t _
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ -> head t
| Tv_Unknown
| Tv_Uvar _ _
| Tv_Const _
| Tv_Type _
| Tv_Var _
| Tv_BVar _
| Tv_FVar _
| Tv_UInst _ _
| Tv_Arrow _ _
| Tv_Unsupp -> t
(** Checks if a term `t` is equal to some FV (a top level name).
Ignores universes and ascriptions. *) | false | true | FStar.Reflection.V2.Derived.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_fvar (t: term) (nm: string) : bool | [] | FStar.Reflection.V2.Derived.is_fvar | {
"file_name": "ulib/FStar.Reflection.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> nm: Prims.string -> Prims.bool | {
"end_col": 16,
"end_line": 234,
"start_col": 4,
"start_line": 231
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.